From 44aa2d4f4a559f5f7343ed471520b68a5627b245 Mon Sep 17 00:00:00 2001 From: Aaron Friel Date: Wed, 16 Nov 2022 13:00:24 -0800 Subject: [PATCH] cli: Add fully qualified stack reference to pulumi about --- pkg/cmd/pulumi/about.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/pulumi/about.go b/pkg/cmd/pulumi/about.go index deb94b173588..84a3e83b10c9 100644 --- a/pkg/cmd/pulumi/about.go +++ b/pkg/cmd/pulumi/about.go @@ -86,16 +86,17 @@ type summaryAbout struct { // We use pointers here to allow the field to be nullable. When // constructing, we either fill in a field or add an error. We still // indicate that the field should be present when we serialize the struct. - Plugins []pluginAbout `json:"plugins"` - Host *hostAbout `json:"host"` - Backend *backendAbout `json:"backend"` - CurrentStack *currentStackAbout `json:"currentStack"` - CLI *cliAbout `json:"cliAbout"` - Runtime *projectRuntimeAbout `json:"runtime"` - Dependencies []programDependencyAbout `json:"dependencies"` - ErrorMessages []string `json:"errors"` - Errors []error `json:"-"` - LogMessage string `json:"-"` + Plugins []pluginAbout `json:"plugins"` + Host *hostAbout `json:"host"` + Backend *backendAbout `json:"backend"` + CurrentStack *currentStackAbout `json:"currentStack"` + CLI *cliAbout `json:"cliAbout"` + Runtime *projectRuntimeAbout `json:"runtime"` + Dependencies []programDependencyAbout `json:"dependencies"` + ErrorMessages []string `json:"errors"` + StackReference string `json:"stackReference"` + Errors []error `json:"-"` + LogMessage string `json:"-"` } func getSummaryAbout(ctx context.Context, transitiveDependencies bool, selectedStack string) summaryAbout { @@ -188,6 +189,16 @@ func getSummaryAbout(ctx context.Context, transitiveDependencies bool, selectedS tmp := getBackendAbout(backend) result.Backend = &tmp } + + if result.CurrentStack != nil && strings.Contains(result.CurrentStack.Name, "/") { + // if the stack name contains a /, it's $org/$stack, so we need to insert project + parts := strings.Split(result.CurrentStack.Name, "/") + result.StackReference = fmt.Sprintf("%v/%v/%v", parts[0], proj.Name, parts[1]) + } else if result.CurrentStack != nil && result.Backend != nil { + // the stack name is $stack with the current user as the org + result.StackReference = fmt.Sprintf("%v/%v/%v", result.Backend.User, proj.Name, result.CurrentStack.Name) + } + return result } @@ -202,6 +213,9 @@ func (summary *summaryAbout) Print() { if summary.Runtime != nil { fmt.Println(summary.Runtime) } + if summary.StackReference != "" { + fmt.Printf("Fully qualified stack name: %v\n\n", summary.StackReference) + } if summary.CurrentStack != nil { fmt.Println(summary.CurrentStack) }