Skip to content

Instantly share code, notes, and snippets.

View APIUM's full-sized avatar

Algy APIUM

  • Melbourne, Australia
View GitHub Profile
-antigen-parse-args () {
576 # An argument parsing functionality to parse arguments the *antigen* way :).
577 # Takes one first argument (called spec), which dictates how to parse and
578 # the rest of the arguments are parsed. Outputs a piece of valid shell code
579 # that can be passed to `eval` inside a function which creates the arguments
580 # and their values as local variables. Suggested use is to set the defaults
581 # to all arguments first and then eval the output of this function.
582
583 # Spec: Only long argument supported. No support for parsing short options.
584 # The spec must have two sections, separated by a `;`.
-antigen-parse-args () {
local spec="$1"
shift
spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')"
local code=''
--add-var () {
test -z "$code" || code="$code\n"
code="${code}local $1='$2'"
}
local positional_args="$(echo "$spec" | cut -d\; -f1)"