diff --git a/README.md b/README.md index 5718c652..4fdde211 100644 --- a/README.md +++ b/README.md @@ -379,7 +379,8 @@ print-os: ### Help -Running `task help` lists all tasks with a description. The following taskfile: +Running `task --list` (or `task -l`) lists all tasks with a description. +The following taskfile: ```yml build: @@ -404,8 +405,8 @@ css: would print the following output: ```bash -build Build the go binary. -test Run all the go tests. +* build: Build the go binary. +* test: Run all the go tests. ``` ## Watch tasks (experimental) diff --git a/cmd/task/task.go b/cmd/task/task.go index ca1628be..4d6cdd15 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -14,7 +14,7 @@ var ( version = "master" ) -const usage = `Usage: task [-ifwv] [--init] [--force] [--watch] [--verbose] [task...] +const usage = `Usage: task [-ilfwv] [--init] [--list] [--force] [--watch] [--verbose] [task...] Runs the specified task(s). Falls back to the "default" task if no task name was specified, or lists all tasks if an unknown task name was specified. @@ -45,6 +45,7 @@ func main() { var ( versionFlag bool init bool + list bool force bool watch bool verbose bool @@ -52,6 +53,7 @@ func main() { pflag.BoolVar(&versionFlag, "version", false, "show Task version") pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yml in the current folder") + pflag.BoolVarP(&list, "list", "l", false, "lists tasks with description of current Taskfile") pflag.BoolVarP(&force, "force", "f", false, "forces execution even when the task is up-to-date") pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task") pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode") @@ -86,6 +88,11 @@ func main() { log.Fatal(err) } + if list { + e.PrintTasksHelp() + return + } + args := pflag.Args() if len(args) == 0 { log.Println("task: No argument given, trying default task") diff --git a/help.go b/help.go index d8053818..c5919bc9 100644 --- a/help.go +++ b/help.go @@ -6,7 +6,8 @@ import ( "text/tabwriter" ) -func (e *Executor) printExistingTasksHelp() { +// PrintTasksHelp prints help os tasks that have a description +func (e *Executor) PrintTasksHelp() { tasks := e.tasksWithDesc() if len(tasks) == 0 { return @@ -16,7 +17,7 @@ func (e *Executor) printExistingTasksHelp() { // Format in tab-separated columns with a tab stop of 8. w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0) for _, task := range tasks { - fmt.Fprintln(w, fmt.Sprintf("- %s:\t%s", task, e.Tasks[task].Desc)) + fmt.Fprintln(w, fmt.Sprintf("* %s:\t%s", task, e.Tasks[task].Desc)) } w.Flush() } diff --git a/task.go b/task.go index 0c24d839..abb09db9 100644 --- a/task.go +++ b/task.go @@ -85,7 +85,7 @@ func (e *Executor) Run(args ...string) error { for _, a := range args { if _, ok := e.Tasks[a]; !ok { // FIXME: move to the main package - e.printExistingTasksHelp() + e.PrintTasksHelp() return &taskNotFoundError{taskName: a} } }