From bdc26d712a4ea878e6f0e8802b0d33dededb54d7 Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Tue, 22 Sep 2020 19:13:47 +0200 Subject: [PATCH] fix(cli): require project definition for destroy --- commands/deploy.go | 2 +- commands/destroy.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/commands/deploy.go b/commands/deploy.go index 5bd4d7b..c66d6bf 100644 --- a/commands/deploy.go +++ b/commands/deploy.go @@ -14,7 +14,7 @@ import ( // DeployApplication is a command object for Cobra that provides the deploy command var DeployApplication = &cobra.Command{ Use: "deploy [path to project definition] [ipv4 address]", - Example: "deploy ./my_project_definition.yml 192.168.178.14", + Example: "deploy ./my_project.yml 192.168.178.14", Short: "Deploy a project onto the target server", Long: `deploy will deploy the given project onto the server`, Args: cobra.ExactArgs(2), diff --git a/commands/destroy.go b/commands/destroy.go index 2ac03a4..3f85a76 100644 --- a/commands/destroy.go +++ b/commands/destroy.go @@ -3,6 +3,8 @@ package commands import ( "fmt" "os" + "path/filepath" + "strings" "sync" "github.com/spf13/cobra" @@ -13,8 +15,8 @@ import ( // DestroyApplication is a command object for Cobra that provides the destroy command var DestroyApplication = &cobra.Command{ - Use: "destroy [project name] [ipv4 address]", - Example: "destroy my_project_name 192.168.178.14", + Use: "destroy [path to project definition] [ipv4 address]", + Example: "destroy ./my_project.yml 192.168.178.14", Short: "Destroy a deployed project on a target server", Long: `destroy will tear down the given project that has been deployed onto the server`, Args: cobra.ExactArgs(2), @@ -27,11 +29,13 @@ var DestroyApplication = &cobra.Command{ // Generate Inventory file inventoryFile, err := ansible.CreateInventoryFile( ansible.IPAddress(args[1]), + ansible.ProjectDefinitionFile(args[0]), ) + if err == nil { defer os.Remove(inventoryFile) options := make(map[string]string) - options["project_name"] = args[0] + options["project_name"] = strings.TrimSuffix(strings.TrimSuffix(filepath.Base(args[0]), ".yml"), ".yaml") err = routines.ExecAnsiblePlaybook("application-destroy", inventoryFile, options) }