pulumi/cmd/env_init.go
Matt Ellis 93ab134bbb Have the CLI keep track of the current environment
Previously, the engine was concered with maintaing information about
the currently active environment. Now, the CLI is in charge of
this. As part of this change, the engine can now assume that every
environment has a non empty name (and I've added asserts on the
entrypoints of the engine API to ensure that any consumer of the
engine passes a non empty environment name)
2017-10-02 16:57:41 -07:00

46 lines
1.2 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package cmd
import (
"fmt"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/pkg/tokens"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
)
func newEnvInitCmd() *cobra.Command {
return &cobra.Command{
Use: "init <env>",
Short: "Create an empty environment with the given name, ready for updates",
Long: "Create an empty environment with the given name, ready for updates\n" +
"\n" +
"This command creates an empty environment with the given name. It has no resources,\n" +
"but afterwards it can become the target of a deployment using the `update` command.",
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
// Read in the name of the environment to use.
if len(args) == 0 {
return errors.New("missing required environment name")
}
envName := tokens.QName(args[0])
if _, err := lumiEngine.GetEnvironmentInfo(envName); err == nil {
return fmt.Errorf("environment '%v' already exists", envName)
}
err := lumiEngine.InitEnv(envName)
if err != nil {
return err
}
return setCurrentEnv(envName, false)
}),
}
}