-
-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Allow shorter syntax for tasks with default configuration #240
Changes from all commits
c3f833d
405c99f
6690bec
0ebd182
5897dbb
a665d28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,61 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { | |
} | ||
return nil | ||
} | ||
|
||
func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
var task struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @jaedle, IMHO you don't need to copy the entire task struct into this function. Just try to marshal the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I just remembered that we also have alternative command syntaxes, like That's easy to do, though. Just check for |
||
Task string | ||
Cmds []*Cmd | ||
Deps []*Dep | ||
Desc string | ||
Summary string | ||
Sources []string | ||
Generates []string | ||
Status []string | ||
Preconditions []*Precondition | ||
Dir string | ||
Vars Vars | ||
Env Vars | ||
Silent bool | ||
Method string | ||
Prefix string | ||
IgnoreError bool `yaml:"ignore_error"` | ||
} | ||
|
||
err := unmarshal(&task) | ||
if err != nil { | ||
var short []string | ||
err := unmarshal(&short) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, cmd := range short { | ||
t.Cmds = append(t.Cmds, &Cmd{ | ||
Cmd: cmd, | ||
}) | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
t.Task = task.Task | ||
t.Cmds = task.Cmds | ||
t.Deps = task.Deps | ||
t.Desc = task.Desc | ||
t.Summary = task.Summary | ||
t.Sources = task.Sources | ||
t.Generates = task.Generates | ||
t.Status = task.Status | ||
t.Preconditions = task.Preconditions | ||
t.Dir = task.Dir | ||
t.Vars = task.Vars | ||
t.Env = task.Env | ||
t.Silent = task.Silent | ||
t.Method = task.Method | ||
t.Prefix = task.Prefix | ||
t.IgnoreError = task.IgnoreError | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||
version: '3' | ||||
|
||||
tasks: | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
run: | ||||
cmds: | ||||
- task: single-cmd | ||||
- task: multiple-cmds | ||||
|
||||
single-cmd: | ||||
cmds: | ||||
- echo "single-line-short-task" | ||||
|
||||
multiple-cmds: | ||||
- echo "multiple-cmds-short-tasks-1" | ||||
- echo "multiple-cmds-short-tasks-2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
task: echo "single-line-short-task" | ||
single-line-short-task | ||
task: echo "multiple-cmds-short-tasks-1" | ||
multiple-cmds-short-tasks-1 | ||
task: echo "multiple-cmds-short-tasks-2" | ||
multiple-cmds-short-tasks-2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the suggestion made on
func (t *Task) UnmarshalYAML
, we should re-add this reflect tag.