pulumi/cmd/env_select.go
joeduffy 3d74eac67d Make major commands more pleasant
This change eliminates the need to constantly type in the environment
name when performing major commands like configuration, planning, and
deployment.  It's probably due to my age, however, I keep fat-fingering
simple commands in front of investors and I am embarrassed!

In the new model, there is a notion of a "current environment", and
I have modeled it kinda sorta just like Git's notion of "current branch."

By default, the current environment is set when you `init` something.
Otherwise, there is the `coco env select <env>` command to change it.
(Running this command w/out a new <env> will show you the current one.)

The major commands `config`, `plan`, `deploy`, and `destroy` will prefer
to use the current environment, unless it is overridden by using the
--env flag.  All of the `coco env <cmd> <env>` commands still require the
explicit passing of an environment which seems reasonable since they are,
after all, about manipulating environments.

As part of this, I've overhauled the aging workspace settings cruft,
which had fallen into disrepair since the initial prototype.
2017-03-21 19:23:32 -07:00

37 lines
996 B
Go

// Copyright 2017 Pulumi, Inc. All rights reserved.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/pulumi/coconut/pkg/tokens"
)
func newEnvSelectCmd() *cobra.Command {
return &cobra.Command{
Use: "select [<env>]",
Aliases: []string{"checkout", "switch"},
Short: "Switch the current workspace to the given environment",
Long: "Switch the current workspace to the given environment. This allows you to use\n" +
"other commands like `config`, `plan`, and `deploy` without needing to specify the\n" +
"environment name each and every time.\n" +
"\n" +
"If no <env> argument is supplied, the current environment is printed.",
Run: runFunc(func(cmd *cobra.Command, args []string) error {
// Read in the name of the environment to switch to.
if len(args) == 0 {
if name := getCurrentEnv(); name != "" {
fmt.Println(name)
}
} else {
name := tokens.QName(args[0])
setCurrentEnv(name, true)
}
return nil
}),
}
}