-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTaskfile
64 lines (52 loc) · 2.1 KB
/
Taskfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
# A Taskfile is just a bash script that will be sourced and run by taskit.
#
# You can also divide your Taskfile into multiple scripts and source them
# here.
#
# NOTE: Taskit stores the names of the tasks in a TASKS array, in their
# definition order.
# Taskit should work with set -e and/or set -u.
# (probably not with set -o pipefail though, not tested)
set -eu
# A task is a function with a `Task::` prefix in its name.
Task::hello () { echo hello world; }
# Comments right before the task will be parsed as the task's help doc.
#
Task::mytask () {
# Null commands that begin with '@attr ...' at the beginning of a task body
# declare attributes for the task:
: @desc "A simple task"
# Only tasks with @desc will be shown in `taskit -t`.
# You can declare parameters for a task so that it can be run with arguments.
: @param name! "your name"
: @param greeting "words to greet with"
: @param rest% "rest of named arguments collected in an array"
: @needs count-from-one to=3 # dependency with arguments will ALWAYS be run.
: @needs count-from-one count-from-one # dependency without arguments only runs ONCE.
# a non-zero exit status of a task function stops taskit from
# running the remaining tasks. This is the default.
: @ignore_status no
# switch the working directory of a task; the default is no cd.
: @cwd /tmp
# In the code below, notice that the parameters are referenced with a '_' prefix.
# Also, that the slurpy(%) parameter(rest) collects unknown arguments in an array.
echo "${_greeting:-Hello}, $_name"
echo "I'm in $PWD"
echo
if (( ${#_rest[*]} )); then
echo "The rest of named arguments are:"
local key
for key in "${!_rest[@]}"; do
echo "$key=${_rest[$key]}"
done
fi
}
Task::count-from-one () {
: @desc "Prints whole numbers, one per line, from 1 up to 'to', inclusive."
: @param to=5 "The number to count up to. (must be an interger >=1)"
local i
for (( i=1; i <= _to; i++ )); do
echo $i
done
}