Support Required Options; Support Default Option Values - v0.10.0
About
Run is task runner that helps you easily manage and invoke small scripts and wrappers.
Do you find yourself using tools like make to manage non build-related scripts?
Build tools are great, but they are not optimized for general script management.
Run aims to be better at managing small scripts and wrappers, while incorporating a familiar make-like syntax.
What's Changed in v0.10.0
- feat: Support required options; Support default option values by @TekWizely in #62
Full Changelog: v0.9.1...v0.10.0
Making Options Required
You can now use ! to indicate that an option is required:
Runfile
##
# Hello world example.
# Prints "Hello, <name>".
# OPTION NAME! -n,--name <name> Name to say hello to
hello:
echo "Hello, ${NAME}"
Required Indicator on Help Text
Required options will be indicated in help text:
$ run help hello
hello:
Hello world example.
Prints "Hello, <name>".
Options:
-h, --help
Show full help screen
-n, --name <name> (required)
Name to say hello to
Error When Required Option Not Provided
An error will be generated if a required option is not provided:
$ run hello
hello: ERROR: Missing required option:
-n, --name <name>
Name to say hello to
Providing A Default Option Value
You can now use ?= to specify a default value for an option, which will be used if the option is not provided:
# OPTION NAME ?= Newman -n,--name <name> Name to say hello to
The default value will be used if you invoke the command without explicitly providing the option:
output with default value
$ run hello
Hello, Newman
Note: Any standard variable assignment value can be used (quoted strings, variable references, etc)
Default Indicator on Help Text
Default values will be indicated in help text:
-n, --name <name> (default: Newman)
Boolean Default Option Values
You can specify a default value for boolean options, but they behave slightly different from standard options:
# OPTION NEWMAN ?= enabled --newman Say hello to Newman
Defaulted Value Always Assumed to be True
The content of the default value text is not used to determine the option's default true/false value.
Why?
Since boolean values are already always false by default, providing a "default value" can only have the effect of defaulting the value to true.
output with defaulted boolean option
$ run hello
Hello, Newman
Default Indicator on Help Text
Even though a boolean option with provided default is always assumed to default to true, the default value text is still useful in that it will be displayed in the help text:
--newman (default: enabled)
This allows you to give better messaging than just "true" or "1" (i.e "enabled" in this example)
Misc
Explicitly Marking Options as "Optional"
Although options are already optional by default, you can now use ? to explicitly indicate that an option is optional:
# OPTION NAME? -n,--name <name> Name to say hello to
NOTE: This exists mostly for parity with ! and behaves the same as when it is not used