mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +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:
		| @@ -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) | ||||
|   | ||||
| @@ -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") | ||||
|   | ||||
							
								
								
									
										5
									
								
								help.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								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() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user