Merge 413d4244d4
into 4d4ff9f1d6
This commit is contained in:
commit
d57d335ce3
|
@ -6,6 +6,8 @@
|
|||
these types virtually unusable in practice.
|
||||
[#8449](https://github.com/pulumi/pulumi/pull/8449)
|
||||
|
||||
- [cli] - Add global flag to print fully qualified stack names. [#7388](https://github.com/pulumi/pulumi/pull/7388)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- [codegen/go] - Respect default values in Pulumi object types.
|
||||
|
|
|
@ -30,6 +30,9 @@ import (
|
|||
"github.com/pulumi/pulumi/sdk/v3/go/common/util/result"
|
||||
)
|
||||
|
||||
// PrintFullStackNames can be set to have stacks print fully qualified names, instead of eliding org or project name.
|
||||
var PrintFullStackNames bool
|
||||
|
||||
// Stack is a cloud stack. This simply adds some cloud-specific properties atop the standard backend stack interface.
|
||||
type Stack interface {
|
||||
backend.Stack
|
||||
|
@ -49,17 +52,19 @@ type cloudBackendReference struct {
|
|||
}
|
||||
|
||||
func (c cloudBackendReference) String() string {
|
||||
curUser, err := c.b.CurrentUser()
|
||||
if err != nil {
|
||||
curUser = ""
|
||||
}
|
||||
|
||||
// If the project names match, we can elide them.
|
||||
if c.b.currentProject != nil && c.project == string(c.b.currentProject.Name) {
|
||||
if c.owner == curUser {
|
||||
return string(c.name) // Elide owner too, if it is the current user.
|
||||
if !PrintFullStackNames {
|
||||
curUser, err := c.b.CurrentUser()
|
||||
if err != nil {
|
||||
curUser = ""
|
||||
}
|
||||
|
||||
// If the project names match, we can elide them.
|
||||
if c.b.currentProject != nil && c.project == string(c.b.currentProject.Name) {
|
||||
if c.owner == curUser {
|
||||
return string(c.name) // Elide owner too, if it is the current user.
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", c.owner, c.name)
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", c.owner, c.name)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/%s/%s", c.owner, c.project, c.name)
|
||||
|
|
24
pkg/backend/httpstate/stack_test.go
Normal file
24
pkg/backend/httpstate/stack_test.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package httpstate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStackString(t *testing.T) {
|
||||
t.Run("PrintsFullNames", func(t *testing.T) {
|
||||
defer func(prev bool) {
|
||||
PrintFullStackNames = prev
|
||||
}(PrintFullStackNames)
|
||||
PrintFullStackNames = true
|
||||
ref := cloudBackendReference{
|
||||
name: "stackName",
|
||||
project: "projectName",
|
||||
owner: "ownerName",
|
||||
b: nil,
|
||||
}
|
||||
|
||||
assert.Equal(t, fmt.Sprintf("%s/%s/%s", ref.owner, ref.project, ref.name), ref.String())
|
||||
})
|
||||
}
|
|
@ -182,6 +182,8 @@ func NewPulumiCmd() *cobra.Command {
|
|||
"Enable verbose logging (e.g., v=3); anything >3 is very verbose")
|
||||
cmd.PersistentFlags().StringVar(
|
||||
&color, "color", "auto", "Colorize output. Choices are: always, never, raw, auto")
|
||||
cmd.PersistentFlags().BoolVar(&httpstate.PrintFullStackNames, "full-name", false,
|
||||
"Print fully qualified stack names")
|
||||
|
||||
// Common commands:
|
||||
// - Getting Started Commands:
|
||||
|
|
|
@ -62,7 +62,7 @@ func newStackCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
if showStackName {
|
||||
fmt.Printf("%s\n", s.Ref().Name())
|
||||
fmt.Printf("%s\n", s.Ref())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue