mirror of
https://github.com/go-task/task.git
synced 2025-02-13 13:59:32 +02:00
Implemented dry run mode
Added a --dry-run flag that compiles and steps through each task, but does not execute them. The commands that would have been run are printed. See #125.
This commit is contained in:
parent
31273cd6ff
commit
1c7ca94d49
@ -635,6 +635,11 @@ tasks:
|
|||||||
- echo "This will print nothing" > /dev/null
|
- echo "This will print nothing" > /dev/null
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Dry Run Mode
|
||||||
|
|
||||||
|
Dry run mode (`--dry-run`) compiles and steps through each task, printing the commands
|
||||||
|
that would be run without executing them. This is useful for debugging your Taskfiles.
|
||||||
|
|
||||||
## Output syntax
|
## Output syntax
|
||||||
|
|
||||||
By default, Task just redirect the STDOUT and STDERR of the running commands
|
By default, Task just redirect the STDOUT and STDERR of the running commands
|
||||||
|
@ -17,7 +17,7 @@ var (
|
|||||||
version = "master"
|
version = "master"
|
||||||
)
|
)
|
||||||
|
|
||||||
const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [task...]
|
const usage = `Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--dry-run] [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.
|
||||||
@ -55,6 +55,7 @@ func main() {
|
|||||||
watch bool
|
watch bool
|
||||||
verbose bool
|
verbose bool
|
||||||
silent bool
|
silent bool
|
||||||
|
dryRun bool
|
||||||
dir string
|
dir string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -66,6 +67,7 @@ func main() {
|
|||||||
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")
|
||||||
pflag.BoolVarP(&silent, "silent", "s", false, "disables echoing")
|
pflag.BoolVarP(&silent, "silent", "s", false, "disables echoing")
|
||||||
|
pflag.BoolVar(&dryRun, "dry-run", false, "compiles and prints tasks in the order that they would be run, without executing them")
|
||||||
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
|
pflag.StringVarP(&dir, "dir", "d", "", "sets directory of execution")
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
@ -91,6 +93,7 @@ func main() {
|
|||||||
Verbose: verbose,
|
Verbose: verbose,
|
||||||
Silent: silent,
|
Silent: silent,
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
|
DryRun: dryRun,
|
||||||
|
|
||||||
Context: getSignalContext(),
|
Context: getSignalContext(),
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ function __list() {
|
|||||||
|
|
||||||
_arguments \
|
_arguments \
|
||||||
'(-d --dir)'{-d,--dir}': :_files' \
|
'(-d --dir)'{-d,--dir}': :_files' \
|
||||||
|
'(--dry-run)'--dry-run \
|
||||||
'(-f --force)'{-f,--force} \
|
'(-f --force)'{-f,--force} \
|
||||||
'(-i --init)'{-i,--init} \
|
'(-i --init)'{-i,--init} \
|
||||||
'(-l --list)'{-l,--list} \
|
'(-l --list)'{-l,--list} \
|
||||||
|
5
task.go
5
task.go
@ -35,6 +35,7 @@ type Executor struct {
|
|||||||
Watch bool
|
Watch bool
|
||||||
Verbose bool
|
Verbose bool
|
||||||
Silent bool
|
Silent bool
|
||||||
|
DryRun bool
|
||||||
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
|
||||||
@ -211,6 +212,10 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
|
|||||||
e.Logger.Errf(cmd.Cmd)
|
e.Logger.Errf(cmd.Cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
stdOut := e.Output.WrapWriter(e.Stdout, t.Prefix)
|
stdOut := e.Output.WrapWriter(e.Stdout, t.Prefix)
|
||||||
stdErr := e.Output.WrapWriter(e.Stderr, t.Prefix)
|
stdErr := e.Output.WrapWriter(e.Stderr, t.Prefix)
|
||||||
defer stdOut.Close()
|
defer stdOut.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user