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