2017-06-26 23:46:34 +02:00
|
|
|
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
|
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-08-02 18:25:22 +02:00
|
|
|
"github.com/pulumi/pulumi-fabric/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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't remove environments that still have resources.
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 20:50:47 +02:00
|
|
|
if !force && info.Snapshot != nil && len(info.Snapshot.Resources) > 0 {
|
2017-04-19 23:46:50 +02:00
|
|
|
return errors.Errorf(
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 20:50:47 +02:00
|
|
|
"'%v' still has resources; removal rejected; pass --force to override", info.Target.Name)
|
2017-03-06 15:32:39 +01:00
|
|
|
}
|
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 ||
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 20:50:47 +02:00
|
|
|
confirmPrompt("This will permanently remove the '%v' environment!", info.Target.Name) {
|
|
|
|
removeTarget(info.Target)
|
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
|
|
|
|
}
|