This commit is contained in:
svangordon-fruit 2021-11-25 07:40:09 +05:30 committed by GitHub
commit d57d335ce3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 11 deletions

View file

@ -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.

View file

@ -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)

View 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())
})
}

View file

@ -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:

View file

@ -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
}