I want to add some options to my custom shell script. I can show it to you since it is not top secret content :-P
In my experience, there are two option types, set and unset options: set options are typically double-hyphenized, of type --key=value, but can also appear as ordered tuple -k value. Unset options are either short -k or long --key.
From a general perspective, we want to define options, such that they have default configurations and short and long variants. I tried thinking about it, but my current inexperience only allows me to use already defined commands.
There are some special tags, like --help/-h and --version/-v, but I think we have much work already. My attempt so far is below:
UNSET_OPTIONS_SHORT=(
"-ut1"
"-ut2"
)
UNSET_OPTIONS_LONG=(
"--unset_tag_1"
"--unset_tag_2"
)
UNSET_OPTIONS_DEFAULT=(
"true"
"false"
)
SET_OPTIONS_SHORT=(
"--st1"
"--st2"
)
SET_OPTIONS_LONG=(
"--set_tag_1"
"--set_tag_2"
)
SET_OPTIONS_DEFAULT=(
"42"
"mango"
)
SET_OPTIONS_DELIMITER="="
ARGS=( "${@}" )
for arg in ${ARGS[@]}; do
# parse and identify arguments into between options and inputs
# It must early-fail in case it cannot parse options,
# either short or long formats
done
getopts?"-ut1"is not a "short option" -- short options are one single letter. "-ut1" is the same as "-u -t -1"