mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
Dry run small code style changes
This commit is contained in:
@@ -55,7 +55,7 @@ func main() {
|
|||||||
watch bool
|
watch bool
|
||||||
verbose bool
|
verbose bool
|
||||||
silent bool
|
silent bool
|
||||||
dryRun bool
|
dry bool
|
||||||
dir string
|
dir string
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -67,7 +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", false, "compiles and prints tasks in the order that they would be run, without executing them")
|
pflag.BoolVar(&dry, "dry", 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()
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ func main() {
|
|||||||
Verbose: verbose,
|
Verbose: verbose,
|
||||||
Silent: silent,
|
Silent: silent,
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
DryRun: dryRun,
|
Dry: dry,
|
||||||
|
|
||||||
Context: getSignalContext(),
|
Context: getSignalContext(),
|
||||||
|
|
||||||
|
4
task.go
4
task.go
@@ -35,7 +35,7 @@ type Executor struct {
|
|||||||
Watch bool
|
Watch bool
|
||||||
Verbose bool
|
Verbose bool
|
||||||
Silent bool
|
Silent bool
|
||||||
DryRun bool
|
Dry bool
|
||||||
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ 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 {
|
if e.Dry {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -433,8 +433,8 @@ func TestExpand(t *testing.T) {
|
|||||||
assert.Equal(t, home, strings.TrimSpace(buff.String()))
|
assert.Equal(t, home, strings.TrimSpace(buff.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDryRun(t *testing.T) {
|
func TestDry(t *testing.T) {
|
||||||
const dir = "testdata/dryrun"
|
const dir = "testdata/dry"
|
||||||
|
|
||||||
file := filepath.Join(dir, "file.txt")
|
file := filepath.Join(dir, "file.txt")
|
||||||
_ = os.Remove(file)
|
_ = os.Remove(file)
|
||||||
@@ -445,11 +445,12 @@ func TestDryRun(t *testing.T) {
|
|||||||
Dir: dir,
|
Dir: dir,
|
||||||
Stdout: &buff,
|
Stdout: &buff,
|
||||||
Stderr: &buff,
|
Stderr: &buff,
|
||||||
DryRun: true,
|
Dry: true,
|
||||||
}
|
}
|
||||||
assert.NoError(t, e.Setup())
|
assert.NoError(t, e.Setup())
|
||||||
assert.NoError(t, e.Run(taskfile.Call{Task: "build"}))
|
assert.NoError(t, e.Run(taskfile.Call{Task: "build"}))
|
||||||
|
|
||||||
|
assert.Equal(t, "touch file.txt", strings.TrimSpace(buff.String()))
|
||||||
if _, err := os.Stat(file); err == nil {
|
if _, err := os.Stat(file); err == nil {
|
||||||
t.Errorf("File should not exist %s", file)
|
t.Errorf("File should not exist %s", file)
|
||||||
}
|
}
|
||||||
|
6
testdata/dry/Taskfile.yml
vendored
Normal file
6
testdata/dry/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
build:
|
||||||
|
cmds:
|
||||||
|
- touch file.txt
|
3
testdata/dryrun/Taskfile.yml
vendored
3
testdata/dryrun/Taskfile.yml
vendored
@@ -1,3 +0,0 @@
|
|||||||
build:
|
|
||||||
cmds:
|
|
||||||
- touch file.txt
|
|
Reference in New Issue
Block a user