Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runner: fail on any invalid tasks #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (r *Runtime) groupTaskAndFlagArgs(args []string) (map[string][]string, bool
currFlagsList = []string{}
} else {
foundInvalidTasks = true
logger.Printf("Unrecognized task: %s, ignoring it and following flags\n", arg)
logger.Printf("Unrecognized task: %s\n", arg)
// Note that in this case, currTaskName must be "" to ignore following flags.
}
}
Expand Down Expand Up @@ -204,19 +204,19 @@ func Run(options ...RunOption) {

taskAndFlagArgs := runtime.flags.Args() // command-line arguments that are not flags for taskrunner itself
taskFlagGroups, foundInvalidTasks := runtime.groupTaskAndFlagArgs(taskAndFlagArgs)
if foundInvalidTasks { // fail if any task was invalid
logger.Fatalln("Error: invalid target task(s) found")
return
}

var desiredTasks []string
for taskName := range taskFlagGroups {
desiredTasks = append(desiredTasks, taskName)
}
watchMode := watch
if len(desiredTasks) == 0 {
if foundInvalidTasks { // tasks were specified, but all invalid
logger.Fatalln("Error: invalid target task(s)")
return
} else { // no tasks were specified
desiredTasks = c.DesiredTasks
watchMode = !nonInteractive
}
desiredTasks = c.DesiredTasks
watchMode = !nonInteractive
}
logger.Println("Desired tasks:", strings.Join(desiredTasks, ", "))
logger.Printf("Watch mode: %t\n", watchMode)
Expand Down
4 changes: 2 additions & 2 deletions runner_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TestRunnerRun_FatalScenarios(t *testing.T) {
expectedFatal: false,
},
{
description: "Fatals when task is specified but unknown",
description: "Fatals when an unknown task is specified",
tasks: []*Task{mockTask},
cliArgs: []string{"", "--config", testConfigFile, "unknown/task", "--someFlag"},
cliArgs: []string{"", "--config", testConfigFile, "basic", "unknown/task", "--someFlag"},
expectedFatal: true,
},
}
Expand Down