pulumi/cmd/plan.go
joeduffy e091bde692 Add a plan command; move env destroy to just destroy
This change adds a `coco plan` command which is simply a shortcut
to the more verbose `coco deploy --dry-run`.  This will make demos
flow nicer and elevates planning, an important activity, to a more
prominent position.  The `--dry-run` (aka `-n`) flag is still there.

This change also renames `coco env destroy` to just `coco destroy`.
This is consistent with deploy and plan being at the top-level.  We
now use `coco env` purely for evironment management commands (init,
config, rm, etc).
2017-03-15 15:40:06 -07:00

71 lines
2.5 KiB
Go

// Copyright 2017 Pulumi, Inc. All rights reserved.
package cmd
import (
"github.com/spf13/cobra"
)
func newPlanCmd() *cobra.Command {
var analyzers []string
var showConfig bool
var showReplaceSteps bool
var showUnchanged bool
var summary bool
var output string
var cmd = &cobra.Command{
Use: "plan <env> [<package>] [-- [<args>]]",
Aliases: []string{"dryrun"},
Short: "Show a plan to update, create, and delete an environment's resources",
Long: "Show a plan to update, create, and delete an environment's resources\n" +
"\n" +
"This command displays a plan to update an existing environment whose state is represented by\n" +
"an existing snapshot file. The new desired state is computed by compiling and evaluating an\n" +
"executable package, and extracting all resource allocations from its resulting object graph.\n" +
"This graph is compared against the existing state to determine what operations must take\n" +
"place to achieve the desired state. No changes to the environment will actually take place.\n" +
"\n" +
"By default, the package to execute is loaded from the current directory. Optionally, an\n" +
"explicit path can be provided using the [package] argument.",
Run: runFunc(func(cmd *cobra.Command, args []string) error {
info, err := initEnvCmd(cmd, args)
if err != nil {
return err
}
defer info.Close()
apply(cmd, info, applyOptions{
Delete: false,
DryRun: true,
Analyzers: analyzers,
ShowConfig: showConfig,
ShowReplaceSteps: showReplaceSteps,
ShowUnchanged: showUnchanged,
Summary: summary,
Output: output,
})
return nil
}),
}
cmd.PersistentFlags().StringSliceVar(
&analyzers, "analyzer", []string{},
"Run one or more analyzers as part of this deployment")
cmd.PersistentFlags().BoolVar(
&showConfig, "show-config", false,
"Show configuration keys and variables")
cmd.PersistentFlags().BoolVar(
&showReplaceSteps, "show-replace-steps", false,
"Show detailed resource replacement creates and deletes; normally shows as a single step")
cmd.PersistentFlags().BoolVar(
&showUnchanged, "show-unchanged", false,
"Show resources that needn't be updated because they haven't changed, alongside those that do")
cmd.PersistentFlags().BoolVarP(
&summary, "summary", "s", false,
"Only display summarization of resources and plan operations")
cmd.PersistentFlags().StringVarP(
&output, "output", "o", "",
"Serialize the resulting plan to a file instead of simply printing it")
return cmd
}