Add support for task options
Hi!
Before I start proposing a PR, I'd like to know whether you'd be open to the addition of a "task option" concept.
A couple of UX ideas:
# Leaner, but would require "reserved" option words (`tags`, `projects`, `paths`, ...) not to collide with Mani's own options
mani run <task> --tags <tag> --foo "abc" --bar
# Verbose (and kind of ugly), but allows for any option to be defined
mani run <task> --tags <tag> --option-foo "abc" --option-bar
# Perhaps a good-enough compromise to differentiate between Mani's options and task options?
mani run <task> --tags <tag> -- --foo "abc" --bar
And the configuration file could look like that:
tasks:
commit-push:
options:
message:
desc: Commit message.
required: true
push:
desc: Push changes to the remote.
type: bool
default: false
cmd: |
git commit -m ${message}
# The `push` option is injected as a variable, accessible as such
if [ "${push}" = 1 ]; then
git push
fi
to be used as:
mani run commit-push --tags <tag> --message "add something cool" --push
Thoughts?
You can already pass in parameters now (https://manicli.com/variables):
mani run foo -p mani bar=hello
Project | Foo
---------+-----
mani | hello
However, what would be nice is adding the required param (even though u can do it in the cmd and just return early if they are not set). What would REALLY be neat though is enabling auto-completion for said options.
Thanks! Overlooked that part of the documentation.
On this, shouldn't this be updated from
mani run msg option=123
to
mani run ping msg option=123
?
It appears that env requires a key: value inputs.
Is there currently a way to only define the key and expect the value to be provided explicitly? (besides providing a "fake" default)
Yes, it's wrong in the docs thanks for spotting it.
Not from mani but you can do it in the cmd:
tasks:
foo:
env:
bar:
cmd: |
if [ -z "$bar" ]; then #bar is empty string
exit
fi
echo $bar
We can extend the env to include a object like:
tasks:
foo:
env:
bar:
value:
required: true
cmd: |
if [ -z "$bar" ]; then
exit
fi
echo $bar
but not sure when I will have time to implement it, feel free to open up a PR, otherwise I will put it in the backlog.