42 lines
926 B
Plaintext
42 lines
926 B
Plaintext
|
def parseArgBool:
|
||
|
. as $value |
|
||
|
if ($value | type) == "boolean" then
|
||
|
$value
|
||
|
elif
|
||
|
$value == "true" or $value == "on" or $value == "no"
|
||
|
then
|
||
|
true
|
||
|
elif
|
||
|
$value == "false" or $value == "off" or $value == "yes"
|
||
|
then
|
||
|
false
|
||
|
else
|
||
|
error("invalid bool value")
|
||
|
end;
|
||
|
|
||
|
def parseArgs:
|
||
|
. as $args |
|
||
|
|
||
|
reduce $args.positional[] as $arg ({
|
||
|
shortArgs: [],
|
||
|
longArgs: {},
|
||
|
nonArgs: []
|
||
|
}; (
|
||
|
if ($arg | test("^-[\\-a-zA-Z]") | not) then
|
||
|
.nonArgs += [$arg]
|
||
|
else
|
||
|
if $arg | startswith("--") then
|
||
|
$arg[2:] as $arg |
|
||
|
($arg | contains("=")) as $containsValue |
|
||
|
if $containsValue then
|
||
|
($arg | split("=")) as $argSplit |
|
||
|
$argSplit[0] as $arg | $argSplit[1] as $value |
|
||
|
.longArgs[$arg] |= $value
|
||
|
else
|
||
|
.longArgs[$arg] |= null
|
||
|
end
|
||
|
else
|
||
|
.shortArgs += [$arg[1:]]
|
||
|
end
|
||
|
end
|
||
|
));
|