mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
add silent mode to disable echoing of commands
This commit is contained in:
parent
dc6cb68327
commit
d0b37df615
55
README.md
55
README.md
@ -19,6 +19,7 @@ It aims to be simpler and easier to use then [GNU Make][make].
|
||||
- [Dynamic variables](#dynamic-variables)
|
||||
- [Go's template engine](#gos-template-engine)
|
||||
- [Help](#help)
|
||||
- [Silent mode](#silent-mode)
|
||||
- [Watch tasks](#watch-tasks-experimental)
|
||||
- [Alternative task runners](#alternative-task-runners)
|
||||
|
||||
@ -421,6 +422,60 @@ would print the following output:
|
||||
* test: Run all the go tests.
|
||||
```
|
||||
|
||||
## Silent mode
|
||||
|
||||
Silent mode disables echoing of commands before Task runs it.
|
||||
For the following Taskfile:
|
||||
|
||||
```yml
|
||||
echo:
|
||||
cmds:
|
||||
- echo "Print something"
|
||||
```
|
||||
|
||||
Normally this will be print:
|
||||
|
||||
```sh
|
||||
echo "Print something"
|
||||
Print something
|
||||
```
|
||||
|
||||
With silent mode on, the below will be print instead:
|
||||
|
||||
```sh
|
||||
Print something
|
||||
```
|
||||
|
||||
There's three ways to enable silent mode:
|
||||
|
||||
* At command level:
|
||||
|
||||
```yml
|
||||
echo:
|
||||
cmds:
|
||||
- cmd: echo "Print something"
|
||||
silent: true
|
||||
```
|
||||
|
||||
* At task level:
|
||||
|
||||
```yml
|
||||
echo:
|
||||
cmds:
|
||||
- echo "Print something"
|
||||
silent: true
|
||||
```
|
||||
|
||||
* Or globally with `--silent` or `-s` flag
|
||||
|
||||
If you want to supress stdout instead, just redirect a command to `/dev/null`:
|
||||
|
||||
```yml
|
||||
echo:
|
||||
cmds:
|
||||
- echo "This will print nothing" > /dev/null
|
||||
```
|
||||
|
||||
## Watch tasks (experimental)
|
||||
|
||||
If you give a `--watch` or `-w` argument, task will watch for files changes
|
||||
|
@ -14,7 +14,7 @@ var (
|
||||
version = "master"
|
||||
)
|
||||
|
||||
const usage = `Usage: task [-ilfwv] [--init] [--list] [--force] [--watch] [--verbose] [task...]
|
||||
const usage = `Usage: task [-ilfwvs] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [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.
|
||||
@ -49,6 +49,7 @@ func main() {
|
||||
force bool
|
||||
watch bool
|
||||
verbose bool
|
||||
silent bool
|
||||
)
|
||||
|
||||
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
|
||||
@ -57,6 +58,7 @@ func main() {
|
||||
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.BoolVarP(&silent, "silent", "s", false, "disables echoing")
|
||||
pflag.Parse()
|
||||
|
||||
if versionFlag {
|
||||
@ -79,6 +81,7 @@ func main() {
|
||||
Force: force,
|
||||
Watch: watch,
|
||||
Verbose: verbose,
|
||||
Silent: silent,
|
||||
|
||||
Stdin: os.Stdin,
|
||||
Stdout: os.Stdout,
|
||||
|
16
command.go
16
command.go
@ -7,9 +7,10 @@ import (
|
||||
|
||||
// Cmd is a task command
|
||||
type Cmd struct {
|
||||
Cmd string
|
||||
Task string
|
||||
Vars Vars
|
||||
Cmd string
|
||||
Silent bool
|
||||
Task string
|
||||
Vars Vars
|
||||
}
|
||||
|
||||
// Dep is a task dependency
|
||||
@ -36,6 +37,15 @@ func (c *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
var cmdStruct struct {
|
||||
Cmd string
|
||||
Silent bool
|
||||
}
|
||||
if err := unmarshal(&cmdStruct); err == nil && cmdStruct.Cmd != "" {
|
||||
c.Cmd = cmdStruct.Cmd
|
||||
c.Silent = cmdStruct.Silent
|
||||
return nil
|
||||
}
|
||||
var taskCall struct {
|
||||
Task string
|
||||
Vars Vars
|
||||
|
6
task.go
6
task.go
@ -31,6 +31,7 @@ type Executor struct {
|
||||
Force bool
|
||||
Watch bool
|
||||
Verbose bool
|
||||
Silent bool
|
||||
|
||||
Stdin io.Reader
|
||||
Stdout io.Writer
|
||||
@ -60,6 +61,7 @@ type Task struct {
|
||||
Vars Vars
|
||||
Set string
|
||||
Env Vars
|
||||
Silent bool
|
||||
}
|
||||
|
||||
// Run runs Task
|
||||
@ -194,7 +196,9 @@ func (e *Executor) runCommand(ctx context.Context, t *Task, call Call, i int) er
|
||||
Stderr: e.Stderr,
|
||||
}
|
||||
|
||||
e.println(cmd.Cmd)
|
||||
if !cmd.Silent && !t.Silent && !e.Silent {
|
||||
e.println(cmd.Cmd)
|
||||
}
|
||||
if t.Set != "" {
|
||||
var stdout bytes.Buffer
|
||||
opts.Stdout = &stdout
|
||||
|
@ -185,15 +185,17 @@ func (t *Task) ReplaceVariables(vars Vars) (*Task, error) {
|
||||
Vars: r.replaceVars(t.Vars),
|
||||
Set: r.replace(t.Set),
|
||||
Env: r.replaceVars(t.Env),
|
||||
Silent: t.Silent,
|
||||
}
|
||||
|
||||
if len(t.Cmds) > 0 {
|
||||
new.Cmds = make([]*Cmd, len(t.Cmds))
|
||||
for i, cmd := range t.Cmds {
|
||||
new.Cmds[i] = &Cmd{
|
||||
Task: r.replace(cmd.Task),
|
||||
Cmd: r.replace(cmd.Cmd),
|
||||
Vars: r.replaceVars(cmd.Vars),
|
||||
Task: r.replace(cmd.Task),
|
||||
Silent: cmd.Silent,
|
||||
Cmd: r.replace(cmd.Cmd),
|
||||
Vars: r.replaceVars(cmd.Vars),
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user