Skip to content

Latest commit

 

History

History
163 lines (110 loc) · 2.55 KB

functions.md

File metadata and controls

163 lines (110 loc) · 2.55 KB

Functions

args_add_argument

Add a argument

option description
--action Action store, store_true, store_false (default:store)
--default Default value
--dest Destination variable
--help Usage helper
--metavar Usage argument name (if not set use long/short name)
--required Is required if exists

If error return 1.

args_add_argument [options...] -- [name/flags...]

examples

# positional argument
args_add_argument -- "FOO"
# boolean optional argument
args_add_argument --action "store_true" -- "-f" "--foo"
# not boolean optional argument
args_add_argument --action="store_false" -- "-f" "--foo"
# optional argument
args_add_argument -- "-f" "--foo"

args_parse_arguments

Use after args_add_argument functions.
Convert argument strings to objects and assign them as attributes on the ARGS map.
Previous calls to args_add_argument.
determine exactly what objects are created and how they are assigned.
Execute this with "$@" parameters.

If help option is called return 64 (exit code) else if error return 1 (exit code).

example

args_parse_arguments "$@"

args_set_description

Set a usage description.
Concat all arguments.

example

args_set_description "your description" "message"

args_set_epilog

Set a epilog description.
Concat all arguments.

example

args_set_epilog "your epilog" "message"

args_set_usage_width

Set the widths of usage message.

Parameter Description
$1 padding
$2 argument
$3 separator
$4 help
args_set_usage_width 2 20 2 56

Set the usage witdhs.

args_set_usage_width 2 20 2 56

args_set_usage_width 2 30 2 15

args_set_usage_width 1 21 1 30

args_set_usage

Set a full usage message.
Concat all arguments.

example

args_set_usage "usage: my_prog [options...]" "--" "[args...]"

args_set_alternative

Set alternative mode for getopt.

example

args_set_alternative "true"

args_usage

Show/Generate usage message.

Parameter Description
$1 Name/Path of script

example

args_usage "foo.sh"

args_clean

Clean all map and array for recalled.

example

args_clean

args_debug_values

Show all values of arguments and options.

example

args_debug_values