Skip to content

Commit

Permalink
Added a command to remove the inertia config and take down existing d…
Browse files Browse the repository at this point in the history
…aemon
  • Loading branch information
bwdmonkey committed Jul 10, 2018
1 parent 14cf119 commit 3191c96
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/ubclaunchpad/inertia/client"
"github.com/ubclaunchpad/inertia/common"
"github.com/ubclaunchpad/inertia/local"
)
Expand All @@ -16,6 +17,7 @@ func init() {
Root.PersistentFlags().StringVar(&configFilePath, "config", "inertia.toml", "Specify relative path to Inertia configuration")
Root.AddCommand(cmdInit)
Root.AddCommand(cmdReset)
Root.AddCommand(cmdRemove)
Root.AddCommand(cmdSetConfigProperty)

cmdInit.Flags().String("version", Root.Version, "Specify Inertia daemon version to use")
Expand Down Expand Up @@ -104,6 +106,45 @@ var cmdReset = &cobra.Command{
},
}

var cmdRemove = &cobra.Command{
Use: "remove [name]",
Short: "Remove Inertia in this repository and the daemon in the given remote",
Long: `Remove the existing Inertia configuration from this repository
and takes down the daemon image from the VPS.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
println("WARNING: This will remove your current Inertia configuration")
println("as well as take the daemon and is irreversible. Continue? (y/n)")
var response string
_, err := fmt.Scanln(&response)
if err != nil {
log.Fatal("invalid response - aborting")
}
if response != "y" {
log.Fatal("aborting")
}

// Daemon down
config, path, err := local.GetProjectConfigFromDisk(configFilePath)
if err != nil {
log.Fatal(err)
}
inertia, found := client.NewClient(args[0], config)
if !found {
log.Fatal("remote not found")
}
err = inertia.DaemonDown()
if err != nil {
log.Fatal(err)
}

// Configuration file remove
os.Remove(path)

println("Inertia configuration and daemon removed.")
},
}

var cmdSetConfigProperty = &cobra.Command{
Use: "set [PROPERTY] [VALUE]",
Short: "Set configuration property of the project",
Expand Down

0 comments on commit 3191c96

Please sign in to comment.