mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	add verbose mode (-v flag)
This commit is contained in:
		| @@ -14,7 +14,7 @@ var ( | ||||
| 	version = "master" | ||||
| ) | ||||
|  | ||||
| const usage = `Usage: task [-ifw] [--init] [--force] [--watch] [task...] | ||||
| const usage = `Usage: task [-ifwv] [--init] [--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,12 +45,14 @@ func main() { | ||||
| 		init        bool | ||||
| 		force       bool | ||||
| 		watch       bool | ||||
| 		verbose     bool | ||||
| 	) | ||||
|  | ||||
| 	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(&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") | ||||
| 	pflag.Parse() | ||||
|  | ||||
| 	if versionFlag { | ||||
| @@ -70,8 +72,9 @@ func main() { | ||||
| 	} | ||||
|  | ||||
| 	e := task.Executor{ | ||||
| 		Force: force, | ||||
| 		Watch: watch, | ||||
| 		Force:   force, | ||||
| 		Watch:   watch, | ||||
| 		Verbose: verbose, | ||||
|  | ||||
| 		Stdin:  os.Stdin, | ||||
| 		Stdout: os.Stdout, | ||||
|   | ||||
							
								
								
									
										12
									
								
								log.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								log.go
									
									
									
									
									
								
							| @@ -11,3 +11,15 @@ func (e *Executor) println(args ...interface{}) { | ||||
| func (e *Executor) printfln(format string, args ...interface{}) { | ||||
| 	fmt.Fprintf(e.Stdout, format+"\n", args...) | ||||
| } | ||||
|  | ||||
| func (e *Executor) verbosePrintln(args ...interface{}) { | ||||
| 	if e.Verbose { | ||||
| 		e.println(args...) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (e *Executor) verbosePrintfln(format string, args ...interface{}) { | ||||
| 	if e.Verbose { | ||||
| 		e.printfln(format, args...) | ||||
| 	} | ||||
| } | ||||
|   | ||||
							
								
								
									
										9
									
								
								task.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								task.go
									
									
									
									
									
								
							| @@ -21,10 +21,11 @@ const ( | ||||
|  | ||||
| // Executor executes a Taskfile | ||||
| type Executor struct { | ||||
| 	Tasks Tasks | ||||
| 	Dir   string | ||||
| 	Force bool | ||||
| 	Watch bool | ||||
| 	Tasks   Tasks | ||||
| 	Dir     string | ||||
| 	Force   bool | ||||
| 	Watch   bool | ||||
| 	Verbose bool | ||||
|  | ||||
| 	Stdin  io.Reader | ||||
| 	Stdout io.Writer | ||||
|   | ||||
| @@ -45,6 +45,7 @@ func (e *Executor) handleDynamicVariableContent(value string) (string, error) { | ||||
| 	} | ||||
|  | ||||
| 	result = strings.TrimSpace(result) | ||||
| 	e.verbosePrintfln(`task: dynamic variable: "%s", result: "%s"`, value, result) | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user