This change includes a handful of stack-related CLI formatting improvements that I've been noodling on in the background for a while, based on things that tend to trip up demos and the inner loop workflow. This includes: * If `pulumi stack select` is run by itself, use an interactive CLI menu to let the user select an existing stack, or choose to create a new one. This looks as follows $ pulumi stack select Please choose a stack, or choose to create a new one: abcdef babblabblabble > currentlyselected defcon <create a new stack> and is navigated in the usual way (key up, down, enter). * If a stack name is passed that does not exist, prompt the user to ask whether s/he wants to create one on-demand. This hooks interesting moments in time, like `pulumi stack select foo`, and cuts down on the need to run additional commands. * If a current stack is required, but none is currently selected, then pop the same interactive menu shown above to select one. Depending on the command being run, we may or may not show the option to create a new stack (e.g., that doesn't make much sense when you're running `pulumi destroy`, but might when you're running `pulumi stack`). This again lets you do with a single command what would have otherwise entailed an error with multiple commands to recover from it. * If you run `pulumi stack init` without any additional arguments, we interactively prompt for the stack name. Before, we would error and you'd then need to run `pulumi stack init <name>`. * Colorize some things nicely; for example, now all prompts will by default become bright white.
115 lines
3.8 KiB
Go
115 lines
3.8 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/pulumi/pulumi/pkg/backend"
|
|
"github.com/pulumi/pulumi/pkg/engine"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
)
|
|
|
|
func newUpdateCmd() *cobra.Command {
|
|
var debug bool
|
|
var stack string
|
|
|
|
var message string
|
|
|
|
// Flags for engine.UpdateOptions.
|
|
var analyzers []string
|
|
var color colorFlag
|
|
var parallel int
|
|
var preview bool
|
|
var showConfig bool
|
|
var showReplacementSteps bool
|
|
var showSames bool
|
|
var summary bool
|
|
|
|
var cmd = &cobra.Command{
|
|
Use: "update",
|
|
Aliases: []string{"up"},
|
|
SuggestFor: []string{"deploy", "push"},
|
|
Short: "Update the resources in an stack",
|
|
Long: "Update the resources in an stack\n" +
|
|
"\n" +
|
|
"This command updates an existing stack whose state is represented by the existing checkpoint\n" +
|
|
"file. The new desired state is computed by running a Pulumi program, and extracting all resource\n" +
|
|
"allocations from its resulting object graph. These allocations are then compared against the\n" +
|
|
"existing state to determine what operations must take place to achieve the desired state. This\n" +
|
|
"command results in a checkpoint containing a full snapshot of the stack's new resource state, so\n" +
|
|
"that it may be updated incrementally again later.\n" +
|
|
"\n" +
|
|
"The program to run is loaded from the project in the current directory. Use the `-C` or\n" +
|
|
"`--cwd` flag to use a different directory.",
|
|
Args: cmdutil.NoArgs,
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
|
s, err := requireStack(tokens.QName(stack), true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
proj, root, err := readProject()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
m, err := getUpdateMetadata(message, root)
|
|
if err != nil {
|
|
return errors.Wrap(err, "gathering environment metadata")
|
|
}
|
|
|
|
return s.Update(proj, root, debug, m, engine.UpdateOptions{
|
|
Analyzers: analyzers,
|
|
DryRun: preview,
|
|
Parallel: parallel,
|
|
ShowConfig: showConfig,
|
|
ShowReplacementSteps: showReplacementSteps,
|
|
ShowSames: showSames,
|
|
Summary: summary,
|
|
}, backend.DisplayOptions{
|
|
Color: color.Colorization(),
|
|
})
|
|
}),
|
|
}
|
|
|
|
cmd.PersistentFlags().BoolVarP(
|
|
&debug, "debug", "d", false,
|
|
"Print detailed debugging output during resource operations")
|
|
cmd.PersistentFlags().StringVarP(
|
|
&stack, "stack", "s", "",
|
|
"Choose an stack other than the currently selected one")
|
|
|
|
cmd.PersistentFlags().StringVarP(
|
|
&message, "message", "m", "",
|
|
"Optional message to associate with the update operation")
|
|
|
|
// Flags for engine.UpdateOptions.
|
|
cmd.PersistentFlags().VarP(
|
|
&color, "color", "c", "Colorize output. Choices are: always, never, raw, auto")
|
|
cmd.PersistentFlags().StringSliceVar(
|
|
&analyzers, "analyzer", []string{},
|
|
"Run one or more analyzers as part of this update")
|
|
cmd.PersistentFlags().IntVarP(
|
|
¶llel, "parallel", "p", 0,
|
|
"Allow P resource operations to run in parallel at once (<=1 for no parallelism)")
|
|
cmd.PersistentFlags().BoolVarP(
|
|
&preview, "preview", "n", false,
|
|
"Don't create/delete resources; just preview the planned operations")
|
|
cmd.PersistentFlags().BoolVar(
|
|
&showConfig, "show-config", false,
|
|
"Show configuration keys and variables")
|
|
cmd.PersistentFlags().BoolVar(
|
|
&showReplacementSteps, "show-replacement-steps", false,
|
|
"Show detailed resource replacement creates and deletes instead of a single step")
|
|
cmd.PersistentFlags().BoolVar(
|
|
&showSames, "show-sames", false,
|
|
"Show resources that needn't be updated because they haven't changed, alongside those that do")
|
|
cmd.PersistentFlags().BoolVar(
|
|
&summary, "summary", false,
|
|
"Only display summarization of resources and operations")
|
|
|
|
return cmd
|
|
}
|