Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a number of enhancements to how the
arg_botcmd
decorator works:By default, argparse will print errors, usage and help text directly to
stdout/stderr. It will also raise SystemExit to make the program stop
with an appropriate error code.
While this is appropriate for a CLI program, it is horrible for Err. The
SystemExit causes some strange behaviour where it doesn't make the bot
exit, but does prevent some processing (!restart no longer works, for
example) and the printing to stdout/stderr means you get no feedback
when issuing commands with incorrect arguments.
With these changes, all this output is nicely returned to the user,
instead.
Ensure the command name is used in the usage as well, instead of the
default
sys.arv[0]
which resulted in one oferr.py
,errbot
orrun_tests.py
.Convert — to -- when parsing arg_botcmds
Some clients (looking at you, Telegram) convert certain ASCII character
combinations to nicer-looking unicode representations, which break the
argument parser. Account for this and undo the conversion to avoid user
frustration.
Make "argument unpacking" on arg_botcmd optional
With this change it becomes possible to define a single
args
argumentto hold all the argparser arguments, removing the need to define them in
the function signature itself.
This is useful especially on commands with lots of argument flags, as
otherwise you have to make sure you define all your arguments in just
the right order, which is very error prone.