Working dir task runner, similar to pwd-module
, but supports completion and description through custom data formats
,
or *
need to be exported in order to use ,
Directly
use comma/main.nu *
use comma/utils.nu *
When you enter a directory, if a ,.nu
file exists, it will be loaded. (Currently you need to press the Enter key again to take effect)
Or source
any file that defines $env.comma_scope
and $env.comma
variables
If there is no ,.nu
file in the current directory, executing ,
without arguments will create a new one from the template. If the file exists, list commands.
Tasks are written in $env.comma
and can be nested, and no spaces allowed in name (except testing).
The nodes of the tree can be ordinary records, and the tasks are defined in the closure of the leaf nodes.
This tree will be traversed during completion. For tasks, you can customize the completion behavior.
Customize completion behavior, as well as descriptions, filters, watches, tests, etc. Need to add some special attributes to the record, such as $_.children
, $_.action
, $_.completion
(so $env.comma
and $env.comma_scope
accepts a closure to avoid potential naming conflicts).
'dev run'
| comma fun {|a,s,_|
nu $a.0
} {
watch: { glob: '*.nu', clear: true }
completion: { ls *.nu | get name }
desc: "develop a nu script"
}
Which is equivalent to
$env.comma = {|_|{
dev: {
run: {
$_.action: {|a,s| nu $a.0 }
$_.watch: { glob: '*.nu', clear: true }
$_.completion: { ls *.nu | get name }
$_.desc: "develop a nu script"
}
}
}}
These attributes support aliases like:
attribute | alias |
---|---|
children | sub, s |
description | desc, dsc, d |
action | act, a |
completion | cmp, c |
filter | flt, f |
computed | cpu, u |
watch | wth, w |
tag | |
expect | exp, e, x |
mock | test_args, m |
report | rpt, r |
The closure of the task's action
, completion
accepts two parameters, the rest arguments
after the breadcrumbs and $env.comma_scope
.
computed
and filter
are defined in $env.comma_scope
which is used to share data, in addition to accepting those two parameters, it also accepts a mode
indicating mode (main|completion|test).
if your closure accepts more than two parameters, it can be executed in completion and test modes, otherwise it can only be executed in main mode.
computed
is calculated in the defined order and replaced with the result.
$env.comma_scope = {|_|{
hello: 'hello'
greet: {$_.computed:{|a, s| $'($s.hello): ($a)' }}
}}
filter
is called when it is declared. If a record is returned, it will be merged back to the $env.comma_scope.
'log'
| comma val filter {|a,s,m,_|
do $_.tips 'run filter' `foo`
}
'foo'
| comma dir {
filter: ['log']
}
'foo bar'
| comma fun {|a,s,_|
echo 'hello'
} {
filter: ['log']
}
Which is equivalent to
$env.comma_scope = {|_|{
log: {$_.filter:{|a, s| do $_.tips 'run filter' `foo` }}
}}
$env.comma = {|_|{
foo: {
$_.sub: {
bar: {
$_.action: { echo 'hello' }
$_.filter: ['log']
}
}
$_.filter: ['log']
}
}}
If execute the command in $_.action
with pp
, and pass --print
flag with ,
, only prints the arguments received by pp
without actually executing it.
pp
can be run alone with flag --print
.
pp --print aaa bbbb ccccc dddddd eeeeee [
ffffff gggggggggg [
hhhhhhhhh iiiiiiiiii lllllllll
] mmmmmmmmmmmmm nnnnnnnnnnnn
aaaaaaaaaaaaaaa
xxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzz
jjjjjjjjjjjjj
] oooooooo ppppppppp [qqqqqq [rrrrrr ssssss tttttt] uuuuuu]
If $_.watch
is defined and run with --watch
flag, it will be run in watch mode.
$env.comma = {|_|{
foo: {
$_.watch: {
glob: '*'
op: ['Write', 'Create']
postpone: true
}
}
}}
glob
defaults to*
,op
defaults to['Write']
,postpone
defaults tofalse
- In watch mode (not Polling) inject
$_.watch
(op, path, new_path) into parameter$s
- when the
interval
field is included, it is polling mode(clear
defaults to 'false')
If run with the --test
flag, it will detect that all nodes with $_.expect
under the current and run their actions.
If there is also the --watch flag, it will run in watch mode without defining $_.watch
.
If $_.mock
is closure, call it with $_.comma_scope
to get the result, otherwise it will be used as the result directly.
The result will be passed as arguments to the $_.action
and $_.expect
.
If the result is a nested list, call iteratively multiple times
If $_.expect
is closure, pass it the result of $_.action
, rest arguments and $_.comma_scope
, if return True and the test passes.
If $_.expect
is list, will use the closures in it as a set of tests.
If $_.expect
is a scalar, it is compared directly with the result of actions.
If $_.report
exists and the test fails, execute $_.report
(has a predefined report $_.diff
)
The default template contains vscode-tasks
and outputs a .vscode/tasks.json
.
'vscode-tasks'
| comma fun {
mkdir .vscode
', --vscode -j' | batch ',.nu' | save -f .vscode/tasks.json
} {
d: "generate .vscode/tasks.json"
w: { glob: ',.nu' }
}
- requires
augustocdias.tasks-shell-input
to run$_.completion
closure. - add
!vscode
into$_.desc
to exclude
[build image]
| comma fun {|a,s|
^$env.docker-cli pull $a.0
let tmp = mktemp
$"
FROM ($a.0)
RUN apt update \\
&& apt-get upgrade -y \\
&& DEBIAN_FRONTEND=noninteractive \\
apt-get install -y --no-install-recommends \\
curl ca-certificates \\
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* \\
&& curl -sSL ($a.2) | tar zxf - -C /opt/vendor \\
&& chown -R 33:33 /opt/vendor"
| do $_.outdent
| save -f $tmp
^$env.docker-cli build -f $tmp -t $a.1 .
rm -f $tmp
^$env.docker-cli push $a.1
} {
cmp: {|a,s|
match ($a | length) {
1 => ['ubuntu', 'alpine', 'nginx']
2 => ['target']
_ => ['vendor']
}
}
desc: 'build docker image'
flt: ['log_args']
}
-
computed
in description parameters
- run
- optimize
comma action
- optimize resolve scope
- [-] cpu and flt without parameters would resolve once during initialization
- dry
- dry wrap lines
- accept list
- formatter: outdent
- reload mode (tmpl)
- optimize
- complete
- with args
- scoped test
- pass scoped
- tree map
- test
- tag
- watch mode
- override sub node watch
- args
- allow running on leaf node
- test action
- scope
- filter
- support many expect (list) for one spec
- curl integration
- report
-
$x.report
intest_message
should belist<string>
- diff
-
- run with
nu -c
(dynamic source nu file)
- template
- vscode-tasks
- should panic when identity not exists
- integration
- gen vscode task json file
- tree map
- batch mode
- run complete in batch mode
- Input variables
- pickString
- augustocdias.tasks-shell-input
- allow rest args as
promptString
- clean filter output
- add gen vscode-tasks to template
- test and watch
- gen vscode task json file
- modulize
- refactor with
resolve node
- run
- complete
- fix redundant filter in description
- refactor with
- theme
- poll sep bar
- tips