Skip to content

Commit

Permalink
cli: Add fully qualified stack reference to pulumi about
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFriel committed Nov 16, 2022
1 parent b950cf0 commit 44aa2d4
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions pkg/cmd/pulumi/about.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}
Expand Down

0 comments on commit 44aa2d4

Please sign in to comment.