Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
fix(cli): require project definition for destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Sep 22, 2020
1 parent 5cf48c0 commit bdc26d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 7 additions & 3 deletions commands/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package commands
import (
"fmt"
"os"
"path/filepath"
"strings"
"sync"

"github.com/spf13/cobra"
Expand All @@ -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),
Expand All @@ -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)
}

Expand Down

0 comments on commit bdc26d7

Please sign in to comment.