[CLI] Allow pulumi console to accept a stack name (#6031)

Fixes: #5854

If a stackname is not passed as an argument then it will use the
currently selected stack
This commit is contained in:
Paul Stack 2020-12-31 00:45:32 +00:00 committed by GitHub
parent ee776b3c33
commit a7cabc2519
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View file

@ -8,6 +8,9 @@ CHANGELOG
- Parallelize bulk operations in NodeJS Automation API.
[#6022](https://github.com/pulumi/pulumi/pull/6022)
- [CLI] Allow `pulumi console` to accept a stack name
[#6031](https://github.com/pulumi/pulumi/pull/6031)
## 2.16.2 (2020-12-23)

View file

@ -20,6 +20,7 @@ import (
"github.com/skratchdot/open-golang/open"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/v2/backend"
"github.com/pulumi/pulumi/pkg/v2/backend/display"
"github.com/pulumi/pulumi/pkg/v2/backend/httpstate"
"github.com/pulumi/pulumi/pkg/v2/backend/state"
@ -27,6 +28,7 @@ import (
)
func newConsoleCmd() *cobra.Command {
var stackName string
cmd := &cobra.Command{
Use: "console",
Short: "Opens the current stack in the Pulumi Console",
@ -35,19 +37,35 @@ func newConsoleCmd() *cobra.Command {
opts := display.Options{
Color: cmdutil.GetGlobalColorization(),
}
backend, err := currentBackend(opts)
if err != nil {
return err
}
stack, err := state.CurrentStack(commandContext(), backend)
currentBackend, err := currentBackend(opts)
if err != nil {
return err
}
// Do a type assertion in order to determine if this is a cloud backend based on whether the assertion
// succeeds or not.
cloudBackend, isCloud := backend.(httpstate.Backend)
cloudBackend, isCloud := currentBackend.(httpstate.Backend)
if isCloud {
// we only need to inspect the requested stack if we are using a cloud based backend
var stack backend.Stack
if stackName != "" {
ref, err := currentBackend.ParseStackReference(stackName)
if err != nil {
return err
}
selectedStack, err := currentBackend.GetStack(commandContext(), ref)
if err != nil {
return err
}
stack = selectedStack
} else {
currentStack, err := state.CurrentStack(commandContext(), currentBackend)
if err != nil {
return err
}
stack = currentStack
}
// Open the stack specific URL (e.g. app.pulumi.com/{org}/{project}/{stack}) for this
// stack if a stack is selected and is a cloud stack, else open the cloud backend URL
// home page, e.g. app.pulumi.com.
@ -70,6 +88,8 @@ func newConsoleCmd() *cobra.Command {
return nil
}),
}
cmd.PersistentFlags().StringVarP(
&stackName, "stack", "s", "", "The name of the stack to view")
return cmd
}