These changes enable tracing of Pulumi API calls. The span with which to associate an API call is passed via a `context.Context` parameter. This required plumbing a `context.Context` parameter through a rather large number of APIs, especially in the backend. In general, all API calls are associated with a new root span that exists for essentially the entire lifetime of an invocation of the Pulumi CLI. There were a few places where the plumbing got a bit hairier than I was willing to address with these changes; I've used `context.Background()` in these instances. API calls that receive this context will create new root spans, but will still be traced.
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/pulumi/pulumi/pkg/backend/state"
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
)
|
|
|
|
// newStackSelectCmd handles both the "local" and "cloud" scenarios in its implementation.
|
|
func newStackSelectCmd() *cobra.Command {
|
|
var cloud string
|
|
cmd := &cobra.Command{
|
|
Use: "select [<stack>]",
|
|
Short: "Switch the current workspace to the given stack",
|
|
Long: "Switch the current workspace to the given stack.\n" +
|
|
"\n" +
|
|
"Selecting a stack allows you to use commands like `config`, `preview`, and `update`\n" +
|
|
"without needing to type the stack name each time.\n" +
|
|
"\n" +
|
|
"If no <stack> argument is supplied, you will be prompted to select one interactively.",
|
|
Args: cmdutil.MaximumNArgs(1),
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
|
b, err := currentBackend()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
// A stack was given, ask all known backends about it
|
|
stackRef, stackErr := b.ParseStackReference(args[0])
|
|
if stackErr != nil {
|
|
return stackErr
|
|
}
|
|
|
|
stack, stackErr := b.GetStack(commandContext(), stackRef)
|
|
if stackErr != nil {
|
|
return stackErr
|
|
} else if stack != nil {
|
|
return state.SetCurrentStack(stackRef.String())
|
|
}
|
|
|
|
return errors.Errorf("no stack named '%s' found", stackRef)
|
|
}
|
|
|
|
// If no stack was given, prompt the user to select a name from the available ones.
|
|
stack, err := chooseStack(b, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return state.SetCurrentStack(stack.Name().String())
|
|
|
|
}),
|
|
}
|
|
cmd.PersistentFlags().StringVarP(
|
|
&cloud, "cloud", "c", "", "A URL for the Pulumi Cloud containing the stack to be selected")
|
|
return cmd
|
|
}
|