argbash
argbash copied to clipboard
INCLUDE_PARSING_CODE() but define ARG_... in main script
Currently my main.sh
has something like:
# DEFINE_SCRIPT_DIR([])
# INCLUDE_PARSING_CODE([main.argbash])
# ARGBASH_GO()
And main.argbash
has:
# ARG_OPTIONAL_BOOLEAN([foo],[f],[Use foo])
# ARG_POSITIONAL_SINGLE([bar],[File for bars])
However, it means that anyone reading main.sh
has to reference main.argbash
to see what variables it provides, and I've found myself in the situation of referencing a variable that I'd deleted from the included file.
So, it would be nice if either or both of (a) allow the # ARG_...()
to be defined in the main file and/or (b) auto-add a reminder block to the main file like:
# $_arg_foo: "Use foo"
# $_arg_bar: "File for bars"
Let me rephrase to see whether we are on the same page:
You would basically like to have the generated parsing code in an external file, but you would like to have declarations in the script itself, as they are the natural place where you would expect them to be - the declarations should be in the file's top, whereas the actual code that uses variables produced by those declarations is at the bottom of the file.
Yes, basically that, so when I run argbash
on the main file it writes the parsing code to the INCLUDE_PARSING_CODE()
file (or whatever keyword would work) rather than placing it inline in the m4_ignore([])
block.
EDIT: I just noticed that argbash-init
generates printf
s for the variables:
printf "Value of '%s': %s\\n" 'foo_bar' "$_arg_foo_bar"
Similar but commented code when using argbash
would help, or a copy of body of the print_help()
function.