1
0
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:
Andrey Nering
2017-07-05 20:55:50 -03:00
parent a1d1f73fe7
commit 222b5cb587
4 changed files with 24 additions and 7 deletions

View File

@ -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 {
@ -72,6 +74,7 @@ func main() {
e := task.Executor{
Force: force,
Watch: watch,
Verbose: verbose,
Stdin: os.Stdin,
Stdout: os.Stdout,

12
log.go
View File

@ -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...)
}
}

View File

@ -25,6 +25,7 @@ type Executor struct {
Dir string
Force bool
Watch bool
Verbose bool
Stdin io.Reader
Stdout io.Writer

View File

@ -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
}