2017-05-18 23:51:52 +02:00
|
|
|
// Licensed to Pulumi Corporation ("Pulumi") under one or more
|
|
|
|
// contributor license agreements. See the NOTICE file distributed with
|
|
|
|
// this work for additional information regarding copyright ownership.
|
|
|
|
// Pulumi licenses this file to You under the Apache License, Version 2.0
|
|
|
|
// (the "License"); you may not use this file except in compliance with
|
|
|
|
// the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2017-03-06 15:32:39 +01:00
|
|
|
|
2017-04-12 19:38:12 +02:00
|
|
|
package main
|
2017-03-06 15:32:39 +01:00
|
|
|
|
|
|
|
import (
|
2017-04-19 23:46:50 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
2017-03-07 14:47:42 +01:00
|
|
|
|
2017-05-18 20:38:28 +02:00
|
|
|
"github.com/pulumi/lumi/pkg/util/cmdutil"
|
2017-03-06 15:32:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func newEnvRmCmd() *cobra.Command {
|
|
|
|
var yes bool
|
|
|
|
var force bool
|
|
|
|
var cmd = &cobra.Command{
|
|
|
|
Use: "rm <env>",
|
|
|
|
Short: "Remove an environment and its configuration",
|
|
|
|
Long: "Remove an environment and its configuration\n" +
|
|
|
|
"\n" +
|
|
|
|
"This command removes an environment 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 environment will no longer be available for deployments.",
|
2017-04-12 20:12:25 +02:00
|
|
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
2017-03-07 14:47:42 +01:00
|
|
|
info, err := initEnvCmd(cmd, args)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer info.Close()
|
|
|
|
|
|
|
|
// Don't remove environments that still have resources.
|
2017-03-06 15:32:39 +01:00
|
|
|
if !force && info.Old != nil && len(info.Old.Resources()) > 0 {
|
2017-04-19 23:46:50 +02:00
|
|
|
return errors.Errorf(
|
2017-03-06 15:32:39 +01:00
|
|
|
"'%v' still has resources; removal rejected; pass --force to override", info.Env.Name)
|
|
|
|
}
|
2017-03-07 14:47:42 +01:00
|
|
|
|
|
|
|
// Ensure the user really wants to do this.
|
2017-03-06 15:32:39 +01:00
|
|
|
if yes ||
|
|
|
|
confirmPrompt("This will permanently remove the '%v' environment!", info.Env.Name) {
|
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-22 03:23:32 +01:00
|
|
|
removeEnv(info.Env)
|
2017-03-06 15:32:39 +01:00
|
|
|
}
|
2017-03-07 14:47:42 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}),
|
2017-03-06 15:32:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().BoolVarP(
|
|
|
|
&force, "force", "f", false,
|
|
|
|
"By default, removal of a environment with resources will be rejected; this forces it")
|
|
|
|
cmd.PersistentFlags().BoolVar(
|
|
|
|
&yes, "yes", false,
|
|
|
|
"Skip confirmation prompts, and proceed with removal anyway")
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|