This was not intended, only indentation was intended (no pun indented).
Seriously, omitting the newline makes the -i mode more useful as we can
now use syntax like:
mkusage "topic" \
--
"topics:" \
"${topics[@]}"
That is much less code, especially if the list we wanted to include is
already in array.
Older Bash would let this get away since the output is used with form:
read a b <<<$(_pretty__get_caller)
which joined the parts into single line, which happened to be what we
want.
If function name after the module prefix contained double underscore,
the old code would not parse module name properly, e.g.
foo__bar__baz
would consider 'foo__bar' as module name, when only 'foo' should be
considered.
Move SHELLFU_DEBUG* and SHELLFU_VERBOSE to pretty where they belong
These variables are not specific to shellfu internals but in all ways
specific to pretty.sh module. The prefix is mostly historical cruft.
Let's clean that up.
Old naming is inconsistent from how functions are named, which can be
pretty confusing.
Also, there's no such naming requirement for user's modules; the
recommended way is to use unique project-specific prefix for both
functions and globals.
Risk of conflict should be managed by naming modules uniquely and/or
being careful with deployment in new environments.
Use declare builtin to generate debug output.
We gain support for all Bash types, declare will do the formatting for
us, plus we can easily cover Unset state.
Remove '()' decoration from $caller internal variable. Decorations are
matter of presentations; at this level the brackets are only confusing.
To decide whether a caller is main script or direct descendant thereof,
called main(), use negative index of the stack array FUNCNAME (0 in first
case, 1 in the second). To signal that to the `_pretty_*` plug-ins,
use a dedicated boolean.
This also accounts for cases when a main() function is declared somewhere
else than in the main binary. Older code would simply assume (based
on the name being "main") that it's called from main binary and rewrite
$caller, possibly causing confusion. Now, only the originally intended
special cases behave specially.
This is simply impossible; debug_pipe is wrapper around debug which is
identified soon enough, so "debug_pipe" can't be assigned to $frontend.
Also, _pretty__get_frontend() will never return bracket-decorated
function name.
Do not exclude empty lines when debugging with debug_pipe
The grep throws away all empty lines, no matter if SHELLFU_DEBUG is on
or not.
This seems as terrible idea and I can't find out what wass the reason for
that. (I wonder why everything is not broken due to this; most probably
because nobody really uses debug_pipe.)
Do not exclude anything just if debug is on and caller fits
The exclusion criterion would be true for amy frontend just if debug
was on and the caller fit SHELLFU_DEBUG_EXCLUDE. That is, even warnings
and thoughts from the caller would be muted!
In fact, it's frontend that matters; only debug frontend should be
considered for exclusion. OTOH, we don't need to check SHELLFU_DEBUG as
debug frontends already give up ASAP if that is not set.
We also need to move the frontend rewrite sooner for this to work.
pretty.sh assumes that mkusage is always called from a function named
`usage()` and manipulates $caller based on that. For subcommands,
though, the convention is based on name of the binary anyway, so we can
easily circumvent that limitation.
/dev/stdin will be treated as normal file, albeit `test -s` would detect
it as non-existent. '-' will cause STDIN to be used as wellm but will
omit header.