mirror of
https://github.com/go-task/task.git
synced 2026-06-24 05:05:49 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
361b9b4ce4 | ||
|
|
78792bd11c | ||
|
|
8b38ddfcd9 | ||
|
|
78ddf50d2d | ||
|
|
41a71e1dee | ||
|
|
a5ed8ad58c | ||
|
|
e45ed85b55 | ||
|
|
52474f9103 | ||
|
|
c2587da27d | ||
|
|
26036877b2 | ||
|
|
906cdd9050 | ||
|
|
762662d056 | ||
|
|
1de4b38766 | ||
|
|
6c73ab823b | ||
|
|
5ef1651151 | ||
|
|
8d695bc8d7 | ||
|
|
c892d055ed | ||
|
|
b327e54be1 | ||
|
|
989045489c | ||
|
|
2dc181c75e | ||
|
|
0a6833e9d8 | ||
|
|
8f80fc4e2c |
@@ -63,5 +63,4 @@ brews:
|
|||||||
test:
|
test:
|
||||||
system "#{bin}/task", "--help"
|
system "#{bin}/task", "--help"
|
||||||
url_template: https://github.com/go-task/task/releases/download/{{.Tag}}/{{.ArtifactName}}
|
url_template: https://github.com/go-task/task/releases/download/{{.Tag}}/{{.ArtifactName}}
|
||||||
commit_msg_template: Bump {{.Tag}}
|
skip_upload: true
|
||||||
token: "{{.Env.GORELEASER_TOKEN}}"
|
|
||||||
|
|||||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,6 +1,17 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 3.7.2 - 2021-09-04
|
## v3.8.0 - 2021-09-26
|
||||||
|
|
||||||
|
- Add `interactive: true` setting to improve support for interactive CLI apps
|
||||||
|
([#217](https://github.com/go-task/task/issues/217), [#563](https://github.com/go-task/task/pull/563)).
|
||||||
|
- Fix some `nil` errors
|
||||||
|
([#534](https://github.com/go-task/task/issues/534), [#573](https://github.com/go-task/task/pull/573)).
|
||||||
|
- Add ability to declare an included Taskfile as optional
|
||||||
|
([#519](https://github.com/go-task/task/issues/519), [#552](https://github.com/go-task/task/pull/552)).
|
||||||
|
- Add support for including Taskfiles in the home directory by using `~`
|
||||||
|
([#539](https://github.com/go-task/task/issues/539), [#557](https://github.com/go-task/task/pull/557)).
|
||||||
|
|
||||||
|
## v3.7.3 - 2021-09-04
|
||||||
|
|
||||||
- Add official support to Apple M1 ([#564](https://github.com/go-task/task/pull/564), [#567](https://github.com/go-task/task/pull/567)).
|
- Add official support to Apple M1 ([#564](https://github.com/go-task/task/pull/564), [#567](https://github.com/go-task/task/pull/567)).
|
||||||
- Our [official Homebrew tap](https://github.com/go-task/homebrew-tap) will
|
- Our [official Homebrew tap](https://github.com/go-task/homebrew-tap) will
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ officially supported. On Linux, only `Taskfile.yml` will work, though.
|
|||||||
|
|
||||||
- `version:`
|
- `version:`
|
||||||
- `includes:`
|
- `includes:`
|
||||||
- Configuration ones, like `output:`, `expansions:` or `silent:`
|
- Configuration ones, like `output:` or `silent:`
|
||||||
- `vars:`
|
- `vars:`
|
||||||
- `env:`
|
- `env:`
|
||||||
- `tasks:`
|
- `tasks:`
|
||||||
@@ -60,7 +60,6 @@ version: '3'
|
|||||||
includes:
|
includes:
|
||||||
docker: ./docker/Taskfile.yml
|
docker: ./docker/Taskfile.yml
|
||||||
output: prefixed
|
output: prefixed
|
||||||
expansions: 3
|
|
||||||
vars:
|
vars:
|
||||||
FOO: bar
|
FOO: bar
|
||||||
env:
|
env:
|
||||||
@@ -76,7 +75,6 @@ includes:
|
|||||||
docker: ./docker/Taskfile.yml
|
docker: ./docker/Taskfile.yml
|
||||||
|
|
||||||
output: prefixed
|
output: prefixed
|
||||||
expansions: 3
|
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
FOO: bar
|
FOO: bar
|
||||||
|
|||||||
@@ -154,6 +154,25 @@ includes:
|
|||||||
> This was a deliberate decision to keep use and implementation simple.
|
> This was a deliberate decision to keep use and implementation simple.
|
||||||
> If you disagree, open an GitHub issue and explain your use case. =)
|
> If you disagree, open an GitHub issue and explain your use case. =)
|
||||||
|
|
||||||
|
### Optional includes
|
||||||
|
|
||||||
|
Includes marked as optional will allow Task to continue execution as normal if
|
||||||
|
the included file is missing.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
tests:
|
||||||
|
taskfile: ./tests/Taskfile.yml
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
greet:
|
||||||
|
cmds:
|
||||||
|
- echo "This command can still be successfully executed if ./tests/Taskfile.yml does not exist"
|
||||||
|
```
|
||||||
|
|
||||||
## Task directory
|
## Task directory
|
||||||
|
|
||||||
By default, tasks will be executed in the directory where the Taskfile is
|
By default, tasks will be executed in the directory where the Taskfile is
|
||||||
@@ -931,6 +950,28 @@ $ task default
|
|||||||
|
|
||||||
> The `output` option can also be specified by the `--output` or `-o` flags.
|
> The `output` option can also be specified by the `--output` or `-o` flags.
|
||||||
|
|
||||||
|
## Interactive CLI application
|
||||||
|
|
||||||
|
When running interactive CLI applications inside Task they can sometimes behave
|
||||||
|
weirdly, specially when the [output mode](#output-syntax) is set to something
|
||||||
|
other than `interleaved` (the default), or when interactive apps are ran in
|
||||||
|
parallel with other tasks.
|
||||||
|
|
||||||
|
The `interactive: true` tells Task this is an interactive application, and Task
|
||||||
|
will try to optimize for it:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
cmds:
|
||||||
|
- vim my-file.txt
|
||||||
|
interactive: true
|
||||||
|
```
|
||||||
|
|
||||||
|
If you still have problem running an interactive app through Task, please open
|
||||||
|
an issue about it.
|
||||||
|
|
||||||
## Short task syntax
|
## Short task syntax
|
||||||
|
|
||||||
Starting on Task v3, you can now write tasks with a shorter syntax if they
|
Starting on Task v3, you can now write tasks with a shorter syntax if they
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -1,9 +1,9 @@
|
|||||||
module github.com/go-task/task/v3
|
module github.com/go-task/task/v3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fatih/color v1.12.0
|
github.com/fatih/color v1.13.0
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.4.0
|
||||||
github.com/mattn/go-zglob v0.0.3
|
github.com/mattn/go-zglob v0.0.3
|
||||||
github.com/mitchellh/hashstructure/v2 v2.0.2
|
github.com/mitchellh/hashstructure/v2 v2.0.2
|
||||||
github.com/radovskyb/watcher v1.0.7
|
github.com/radovskyb/watcher v1.0.7
|
||||||
|
|||||||
15
go.sum
15
go.sum
@@ -7,13 +7,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
|
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||||
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||||
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
|
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
|
||||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
||||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
@@ -21,10 +21,11 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
|
||||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
|
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||||
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
github.com/mattn/go-zglob v0.0.3 h1:6Ry4EYsScDyt5di4OI6xw1bYhOqfE5S33Z1OPy+d+To=
|
github.com/mattn/go-zglob v0.0.3 h1:6Ry4EYsScDyt5di4OI6xw1bYhOqfE5S33Z1OPy+d+To=
|
||||||
github.com/mattn/go-zglob v0.0.3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
|
github.com/mattn/go-zglob v0.0.3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
|
||||||
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
|
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
|
||||||
|
|||||||
9
task.go
9
task.go
@@ -415,8 +415,13 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stdOut := e.Output.WrapWriter(e.Stdout, t.Prefix)
|
outputWrapper := e.Output
|
||||||
stdErr := e.Output.WrapWriter(e.Stderr, t.Prefix)
|
if t.Interactive {
|
||||||
|
outputWrapper = output.Interleaved{}
|
||||||
|
}
|
||||||
|
stdOut := outputWrapper.WrapWriter(e.Stdout, t.Prefix)
|
||||||
|
stdErr := outputWrapper.WrapWriter(e.Stderr, t.Prefix)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if _, ok := stdOut.(*os.File); !ok {
|
if _, ok := stdOut.(*os.File); !ok {
|
||||||
if closer, ok := stdOut.(io.Closer); ok {
|
if closer, ok := stdOut.(io.Closer); ok {
|
||||||
|
|||||||
61
task_test.go
61
task_test.go
@@ -755,6 +755,41 @@ func TestIncludesCallingRoot(t *testing.T) {
|
|||||||
tt.Run(t)
|
tt.Run(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIncludesOptional(t *testing.T) {
|
||||||
|
tt := fileContentTest{
|
||||||
|
Dir: "testdata/includes_optional",
|
||||||
|
Target: "default",
|
||||||
|
TrimSpace: true,
|
||||||
|
Files: map[string]string{
|
||||||
|
"called_dep.txt": "called_dep",
|
||||||
|
}}
|
||||||
|
tt.Run(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIncludesOptionalImplicitFalse(t *testing.T) {
|
||||||
|
e := task.Executor{
|
||||||
|
Dir: "testdata/includes_optional_implicit_false",
|
||||||
|
Stdout: ioutil.Discard,
|
||||||
|
Stderr: ioutil.Discard,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := e.Setup()
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, "stat testdata/includes_optional_implicit_false/TaskfileOptional.yml: no such file or directory", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIncludesOptionalExplicitFalse(t *testing.T) {
|
||||||
|
e := task.Executor{
|
||||||
|
Dir: "testdata/includes_optional_explicit_false",
|
||||||
|
Stdout: ioutil.Discard,
|
||||||
|
Stderr: ioutil.Discard,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := e.Setup()
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Equal(t, "stat testdata/includes_optional_explicit_false/TaskfileOptional.yml: no such file or directory", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
func TestSummary(t *testing.T) {
|
func TestSummary(t *testing.T) {
|
||||||
const dir = "testdata/summary"
|
const dir = "testdata/summary"
|
||||||
|
|
||||||
@@ -990,3 +1025,29 @@ func TestRunOnlyRunsJobsHashOnce(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tt.Run(t)
|
tt.Run(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIgnoreNilElements(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
dir string
|
||||||
|
}{
|
||||||
|
{"nil cmd", "testdata/ignore_nil_elements/cmds"},
|
||||||
|
{"nil dep", "testdata/ignore_nil_elements/deps"},
|
||||||
|
{"nil precondition", "testdata/ignore_nil_elements/preconditions"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
var buff bytes.Buffer
|
||||||
|
e := task.Executor{
|
||||||
|
Dir: test.dir,
|
||||||
|
Stdout: &buff,
|
||||||
|
Stderr: &buff,
|
||||||
|
Silent: true,
|
||||||
|
}
|
||||||
|
assert.NoError(t, e.Setup())
|
||||||
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
|
||||||
|
assert.Equal(t, "string-slice-1\n", buff.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
type IncludedTaskfile struct {
|
type IncludedTaskfile struct {
|
||||||
Taskfile string
|
Taskfile string
|
||||||
Dir string
|
Dir string
|
||||||
|
Optional bool
|
||||||
AdvancedImport bool
|
AdvancedImport bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,12 +93,14 @@ func (it *IncludedTaskfile) UnmarshalYAML(unmarshal func(interface{}) error) err
|
|||||||
var includedTaskfile struct {
|
var includedTaskfile struct {
|
||||||
Taskfile string
|
Taskfile string
|
||||||
Dir string
|
Dir string
|
||||||
|
Optional bool
|
||||||
}
|
}
|
||||||
if err := unmarshal(&includedTaskfile); err != nil {
|
if err := unmarshal(&includedTaskfile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
it.Dir = includedTaskfile.Dir
|
|
||||||
it.Taskfile = includedTaskfile.Taskfile
|
it.Taskfile = includedTaskfile.Taskfile
|
||||||
|
it.Dir = includedTaskfile.Dir
|
||||||
|
it.Optional = includedTaskfile.Optional
|
||||||
it.AdvancedImport = true
|
it.AdvancedImport = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
|
"github.com/go-task/task/v3/internal/execext"
|
||||||
"github.com/go-task/task/v3/internal/templater"
|
"github.com/go-task/task/v3/internal/templater"
|
||||||
"github.com/go-task/task/v3/taskfile"
|
"github.com/go-task/task/v3/taskfile"
|
||||||
)
|
)
|
||||||
@@ -42,6 +43,7 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
|
|||||||
includedTask = taskfile.IncludedTaskfile{
|
includedTask = taskfile.IncludedTaskfile{
|
||||||
Taskfile: tr.Replace(includedTask.Taskfile),
|
Taskfile: tr.Replace(includedTask.Taskfile),
|
||||||
Dir: tr.Replace(includedTask.Dir),
|
Dir: tr.Replace(includedTask.Dir),
|
||||||
|
Optional: includedTask.Optional,
|
||||||
AdvancedImport: includedTask.AdvancedImport,
|
AdvancedImport: includedTask.AdvancedImport,
|
||||||
}
|
}
|
||||||
if err := tr.Err(); err != nil {
|
if err := tr.Err(); err != nil {
|
||||||
@@ -49,14 +51,19 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if filepath.IsAbs(includedTask.Taskfile) {
|
path, err := execext.Expand(includedTask.Taskfile)
|
||||||
path = includedTask.Taskfile
|
if err != nil {
|
||||||
} else {
|
return err
|
||||||
path = filepath.Join(dir, includedTask.Taskfile)
|
}
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
path = filepath.Join(dir, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if includedTask.Optional {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ type Task struct {
|
|||||||
Vars *Vars
|
Vars *Vars
|
||||||
Env *Vars
|
Env *Vars
|
||||||
Silent bool
|
Silent bool
|
||||||
|
Interactive bool
|
||||||
Method string
|
Method string
|
||||||
Prefix string
|
Prefix string
|
||||||
IgnoreError bool
|
IgnoreError bool
|
||||||
@@ -59,6 +60,7 @@ func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
Vars *Vars
|
Vars *Vars
|
||||||
Env *Vars
|
Env *Vars
|
||||||
Silent bool
|
Silent bool
|
||||||
|
Interactive bool
|
||||||
Method string
|
Method string
|
||||||
Prefix string
|
Prefix string
|
||||||
IgnoreError bool `yaml:"ignore_error"`
|
IgnoreError bool `yaml:"ignore_error"`
|
||||||
@@ -80,6 +82,7 @@ func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
t.Vars = task.Vars
|
t.Vars = task.Vars
|
||||||
t.Env = task.Env
|
t.Env = task.Env
|
||||||
t.Silent = task.Silent
|
t.Silent = task.Silent
|
||||||
|
t.Interactive = task.Interactive
|
||||||
t.Method = task.Method
|
t.Method = task.Method
|
||||||
t.Prefix = task.Prefix
|
t.Prefix = task.Prefix
|
||||||
t.IgnoreError = task.IgnoreError
|
t.IgnoreError = task.IgnoreError
|
||||||
|
|||||||
7
testdata/ignore_nil_elements/cmds/Taskfile.yml
vendored
Normal file
7
testdata/ignore_nil_elements/cmds/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- echo "string-slice-1"
|
||||||
|
-
|
||||||
11
testdata/ignore_nil_elements/deps/Taskfile.yml
vendored
Normal file
11
testdata/ignore_nil_elements/deps/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
deps:
|
||||||
|
-
|
||||||
|
- task: dep
|
||||||
|
|
||||||
|
dep:
|
||||||
|
cmds:
|
||||||
|
- echo "string-slice-1"
|
||||||
9
testdata/ignore_nil_elements/preconditions/Taskfile.yml
vendored
Normal file
9
testdata/ignore_nil_elements/preconditions/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
preconditions:
|
||||||
|
-
|
||||||
|
- sh: "[ 1 = 1 ]"
|
||||||
|
cmds:
|
||||||
|
- echo "string-slice-1"
|
||||||
1
testdata/includes_optional/.gitignore
vendored
Normal file
1
testdata/includes_optional/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.txt
|
||||||
11
testdata/includes_optional/Taskfile.yml
vendored
Normal file
11
testdata/includes_optional/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
included:
|
||||||
|
taskfile: TaskfileOptional.yml
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- echo "called_dep" > called_dep.txt
|
||||||
11
testdata/includes_optional_explicit_false/Taskfile.yml
vendored
Normal file
11
testdata/includes_optional_explicit_false/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
included:
|
||||||
|
taskfile: TaskfileOptional.yml
|
||||||
|
optional: false
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- echo "Hello, world!"
|
||||||
9
testdata/includes_optional_implicit_false/Taskfile.yml
vendored
Normal file
9
testdata/includes_optional_implicit_false/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
included: TaskfileOptional.yml
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- echo "Hello, world!"
|
||||||
34
variables.go
34
variables.go
@@ -56,6 +56,7 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf
|
|||||||
Vars: nil,
|
Vars: nil,
|
||||||
Env: nil,
|
Env: nil,
|
||||||
Silent: origTask.Silent,
|
Silent: origTask.Silent,
|
||||||
|
Interactive: origTask.Interactive,
|
||||||
Method: r.Replace(origTask.Method),
|
Method: r.Replace(origTask.Method),
|
||||||
Prefix: r.Replace(origTask.Prefix),
|
Prefix: r.Replace(origTask.Prefix),
|
||||||
IgnoreError: origTask.IgnoreError,
|
IgnoreError: origTask.IgnoreError,
|
||||||
@@ -90,34 +91,43 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(origTask.Cmds) > 0 {
|
if len(origTask.Cmds) > 0 {
|
||||||
new.Cmds = make([]*taskfile.Cmd, len(origTask.Cmds))
|
new.Cmds = make([]*taskfile.Cmd, 0, len(origTask.Cmds))
|
||||||
for i, cmd := range origTask.Cmds {
|
for _, cmd := range origTask.Cmds {
|
||||||
new.Cmds[i] = &taskfile.Cmd{
|
if cmd == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
new.Cmds = append(new.Cmds, &taskfile.Cmd{
|
||||||
Task: r.Replace(cmd.Task),
|
Task: r.Replace(cmd.Task),
|
||||||
Silent: cmd.Silent,
|
Silent: cmd.Silent,
|
||||||
Cmd: r.Replace(cmd.Cmd),
|
Cmd: r.Replace(cmd.Cmd),
|
||||||
Vars: r.ReplaceVars(cmd.Vars),
|
Vars: r.ReplaceVars(cmd.Vars),
|
||||||
IgnoreError: cmd.IgnoreError,
|
IgnoreError: cmd.IgnoreError,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(origTask.Deps) > 0 {
|
if len(origTask.Deps) > 0 {
|
||||||
new.Deps = make([]*taskfile.Dep, len(origTask.Deps))
|
new.Deps = make([]*taskfile.Dep, 0, len(origTask.Deps))
|
||||||
for i, dep := range origTask.Deps {
|
for _, dep := range origTask.Deps {
|
||||||
new.Deps[i] = &taskfile.Dep{
|
if dep == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
new.Deps = append(new.Deps, &taskfile.Dep{
|
||||||
Task: r.Replace(dep.Task),
|
Task: r.Replace(dep.Task),
|
||||||
Vars: r.ReplaceVars(dep.Vars),
|
Vars: r.ReplaceVars(dep.Vars),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(origTask.Preconditions) > 0 {
|
if len(origTask.Preconditions) > 0 {
|
||||||
new.Preconditions = make([]*taskfile.Precondition, len(origTask.Preconditions))
|
new.Preconditions = make([]*taskfile.Precondition, 0, len(origTask.Preconditions))
|
||||||
for i, precond := range origTask.Preconditions {
|
for _, precond := range origTask.Preconditions {
|
||||||
new.Preconditions[i] = &taskfile.Precondition{
|
if precond == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
new.Preconditions = append(new.Preconditions, &taskfile.Precondition{
|
||||||
Sh: r.Replace(precond.Sh),
|
Sh: r.Replace(precond.Sh),
|
||||||
Msg: r.Replace(precond.Msg),
|
Msg: r.Replace(precond.Msg),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user