This change implements basic plugin management, but we do not yet actually use the plugins for anything (that comes next). Plugins are stored in `~/.pulumi/plugins`, and are expected to be in the format `pulumi-<KIND>-<NAME>-v<VERSION>[.exe]`. The KIND is one of `analyzer`, `language`, or `resource`, the NAME is a hyphen- delimited name (e.g., `aws` or `foo-bar`), and VERSION is the plugin's semantic version (e.g., `0.9.11`, `1.3.7-beta.a736cf`, etc). This commit includes four new CLI commands: * `pulumi plugin` is the top-level plugin command. It does nothing but show the help text for associated child commands. * `pulumi plugin install` can be used to install plugins manually. If run with no additional arguments, it will compute the set of plugins used by the current project, and download them all. It may be run to explicitly download a single plugin, however, by invoking it as `pulumi plugin install KIND NAME VERSION`. For example, `pulumi plugin install resource aws v0.9.11`. By default, this command uses the cloud backend in the usual way to perform the download, although a separate URL may be given with --cloud-url, just like all other commands that interact with our backend service. * `pulumi plugin ls` lists all plugins currently installed in the plugin cache. It displays some useful statistics, like the size of the plugin, when it was installed, when it was last used, and so on. It sorts the display alphabetically by plugin name, and for plugins with multiple versions, it shows the newest at the top. The command also summarizes how much disk space is currently being consumed by the plugin cache. There are no filtering capabilities yet. * `pulumi plugin prune` will delete plugins from the cache. By default, when run with no arguments, it will delete everything. It may be run with additional arguments, KIND, NAME, and VERSION, each one getting more specific about what it will delete. For instance, `pulumi plugin prune resource aws` will delete all AWS plugin versions, while `pulumi plugin prune resource aws <0.9` will delete all AWS plugins before version 0.9. Unless --yes is passed, the command will confirm the deletion with a count of how many plugins will be affected by the command. We do not yet actually download plugins on demand yet. That will come in a subsequent change.
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/pulumi/pulumi/pkg/backend/state"
|
|
"github.com/pulumi/pulumi/pkg/diag/colors"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
)
|
|
|
|
func newStackRmCmd() *cobra.Command {
|
|
var yes bool
|
|
var force bool
|
|
var cmd = &cobra.Command{
|
|
Use: "rm [<stack-name>]",
|
|
Args: cmdutil.MaximumNArgs(1),
|
|
Short: "Remove a stack and its configuration",
|
|
Long: "Remove a stack and its configuration\n" +
|
|
"\n" +
|
|
"This command removes a stack and its configuration state. Please refer to the\n" +
|
|
"`destroy` command for removing a resources, as this is a distinct operation.\n" +
|
|
"\n" +
|
|
"After this command completes, the stack will no longer be available for updates.",
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
|
// Use the stack provided or, if missing, default to the current one.
|
|
var stack tokens.QName
|
|
if len(args) > 0 {
|
|
stack = tokens.QName(args[0])
|
|
}
|
|
s, err := requireStack(stack, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Ensure the user really wants to do this.
|
|
prompt := fmt.Sprintf("This will permanently remove the '%s' stack!", s.Name())
|
|
if !yes && !confirmPrompt(prompt, string(s.Name())) {
|
|
return errors.New("confirmation declined")
|
|
}
|
|
|
|
hasResources, err := s.Remove(force)
|
|
if err != nil {
|
|
if hasResources {
|
|
return errors.Errorf(
|
|
"'%v' still has resources; removal rejected; pass --force to override", s.Name())
|
|
}
|
|
return err
|
|
}
|
|
|
|
err = deleteAllStackConfiguration(s.Name())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg := fmt.Sprintf("%sStack '%s' has been removed!%s", colors.SpecAttention, s.Name(), colors.Reset)
|
|
fmt.Println(colors.ColorizeText(msg))
|
|
|
|
return state.SetCurrentStack("")
|
|
}),
|
|
}
|
|
|
|
cmd.PersistentFlags().BoolVarP(
|
|
&force, "force", "f", false,
|
|
"By default, removal of a stack with resources will be rejected; this forces it")
|
|
cmd.PersistentFlags().BoolVar(
|
|
&yes, "yes", false,
|
|
"Skip confirmation prompts, and proceed with removal anyway")
|
|
|
|
return cmd
|
|
}
|