mirror of
https://github.com/go-task/task.git
synced 2025-01-06 03:53:54 +02:00
add --list (or -l) flag to print existing tasks
If an inexixtent task is given, the help also prints as before Also fixing README documentation Closes #51
This commit is contained in:
parent
e781ac2512
commit
998935ea55
@ -379,7 +379,8 @@ print-os:
|
|||||||
|
|
||||||
### Help
|
### 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
|
```yml
|
||||||
build:
|
build:
|
||||||
@ -404,8 +405,8 @@ css:
|
|||||||
would print the following output:
|
would print the following output:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
build Build the go binary.
|
* build: Build the go binary.
|
||||||
test Run all the go tests.
|
* test: Run all the go tests.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Watch tasks (experimental)
|
## Watch tasks (experimental)
|
||||||
|
@ -14,7 +14,7 @@ var (
|
|||||||
version = "master"
|
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
|
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.
|
was specified, or lists all tasks if an unknown task name was specified.
|
||||||
@ -45,6 +45,7 @@ func main() {
|
|||||||
var (
|
var (
|
||||||
versionFlag bool
|
versionFlag bool
|
||||||
init bool
|
init bool
|
||||||
|
list bool
|
||||||
force bool
|
force bool
|
||||||
watch bool
|
watch bool
|
||||||
verbose bool
|
verbose bool
|
||||||
@ -52,6 +53,7 @@ func main() {
|
|||||||
|
|
||||||
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
|
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(&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(&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(&watch, "watch", "w", false, "enables watch of the given task")
|
||||||
pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
|
pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
|
||||||
@ -86,6 +88,11 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if list {
|
||||||
|
e.PrintTasksHelp()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
args := pflag.Args()
|
args := pflag.Args()
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
log.Println("task: No argument given, trying default task")
|
log.Println("task: No argument given, trying default task")
|
||||||
|
5
help.go
5
help.go
@ -6,7 +6,8 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *Executor) printExistingTasksHelp() {
|
// PrintTasksHelp prints help os tasks that have a description
|
||||||
|
func (e *Executor) PrintTasksHelp() {
|
||||||
tasks := e.tasksWithDesc()
|
tasks := e.tasksWithDesc()
|
||||||
if len(tasks) == 0 {
|
if len(tasks) == 0 {
|
||||||
return
|
return
|
||||||
@ -16,7 +17,7 @@ func (e *Executor) printExistingTasksHelp() {
|
|||||||
// Format in tab-separated columns with a tab stop of 8.
|
// Format in tab-separated columns with a tab stop of 8.
|
||||||
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
||||||
for _, task := range tasks {
|
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()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
2
task.go
2
task.go
@ -85,7 +85,7 @@ func (e *Executor) Run(args ...string) error {
|
|||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
if _, ok := e.Tasks[a]; !ok {
|
if _, ok := e.Tasks[a]; !ok {
|
||||||
// FIXME: move to the main package
|
// FIXME: move to the main package
|
||||||
e.printExistingTasksHelp()
|
e.PrintTasksHelp()
|
||||||
return &taskNotFoundError{taskName: a}
|
return &taskNotFoundError{taskName: a}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user