From a0267b56227a72003db3666dbeae3171bcb7d971 Mon Sep 17 00:00:00 2001 From: Frank Carey Date: Sun, 22 Jan 2017 02:25:21 -0500 Subject: [PATCH] Issue #50: Provide a check that ensures that either cmd or imports must be set for a command. --- ahoy.go | 5 +++++ tests/missing-cmd.bats | 1 + 2 files changed, 6 insertions(+) diff --git a/ahoy.go b/ahoy.go index debe95a..45bb035 100644 --- a/ahoy.go +++ b/ahoy.go @@ -172,6 +172,11 @@ func getCommands(config Config) []cli.Command { for _, name := range keys { cmd := config.Commands[name] + // Check that a command has 'cmd' OR 'imports' set. + if cmd.Cmd == "" && cmd.Imports == nil { + logger("fatal", "Command ["+name+"] has neither 'cmd' or 'imports' set. Check your yaml file.") + } + newCmd := cli.Command{ Name: name, SkipFlagParsing: true, diff --git a/tests/missing-cmd.bats b/tests/missing-cmd.bats index 133bd78..79f8f0a 100644 --- a/tests/missing-cmd.bats +++ b/tests/missing-cmd.bats @@ -5,4 +5,5 @@ [ $status -ne 0 ] echo "${lines[@]}" [ "${lines[0]}" != "panic: runtime error: invalid memory address or nil pointer dereference" ] + [ "${lines[0]}" == "[fatal] Command [missing-completely] has neither 'cmd' or 'imports' set. Check your yaml file." ] }