argyml
is a command line tool that converts CLI arguments, options and flags into a YAML for downstream parsing
While there are spectacularly powerful CLI tools and shell-scripts, CLI parsing in shell itself remains a manual and error prone process.
argyml
aims to solve this by operating in tandem with yq
to allow for more structured CLI argument parsing.
get_host () {
args=$(argyml $@)
host=$(echo $args | yq eval '.[] | select(.key == "*host*") | .value' )
echo $host
}
$ get_host --host 127.0.0.1
127.0.0.1
Usage of argyml
is really easy, you pass it command-line arguments, options and flags:
argyml some arguments --host 127.0.0.1 -i --another-flag
and receive YAML in standard output:
- type: arg
value: some
- type: arg
value: arguments
- key: --host
type: option
value: 127.0.0.1
- key: -i
type: flag
- key: --another-flag
type: flag
argyml
parses the arguments on naive basis. Implications are the following:
-
it cannot be provided with any sort of schema for options, flags and arguments or their types 1
-
arguments
cannot followflags
, otherwise they will be interpreted asoptions
- Refactor
- Option to directly generate a bash associative array?
- Maybe figure out a way to provide schema for options, flags and arguments?
Footnotes
-
For type casting you should rely on downstream. โฉ