Skip to content

Commit

Permalink
Don't create default commands if they're already defined (init)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Carey committed Dec 16, 2015
1 parent 3d7e5c6 commit d674c31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 7 additions & 4 deletions .ahoy.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ahoyapi: v1
version: 0.0.0
commands:
i:
cmd: "go install ahoy/ahoy.go"
install:
cmd: "go install"
usage: Build ahoy using go install.
test:
cmd: "go test ahoy/ahoy.go"
cmd: "go test"
usage: Test out ahoy using go.
docker:
#cmd: "ahoy help home"
Expand All @@ -14,4 +14,7 @@ commands:
confirm:
cmd: "ahoy -f examples/confirmation.ahoy.yml confirm {{args}}"
usage: Example of importing a single docker command from examples/confirmation.ahoy.yml
hidehelp: true
hide: true
init:
cmd: echo ".ahoy.yml file already exists."
hide: true
9 changes: 6 additions & 3 deletions ahoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ func runCommand(name string, c string) {
}

func addDefaultCommands(commands []cli.Command) []cli.Command {
newCmd := cli.Command{

defaultInitCmd := cli.Command{
Name: "init",
Usage: "Initialize a new .ahoy.yml config file in the current directory.",
Action: func(c *cli.Context) {
Expand All @@ -196,8 +197,10 @@ func addDefaultCommands(commands []cli.Command) []cli.Command {
},
}

// TODO: Check if a command has already been set. Don't add defaults if it has.
commands = append(commands, newCmd)
// Don't add default commands if they've already been set.
if c := app.Command(defaultInitCmd.Name); c == nil {
commands = append(commands, defaultInitCmd)
}
return commands
}

Expand Down

0 comments on commit d674c31

Please sign in to comment.