summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Doffman <mark.doffman@codethink.co.uk>2014-02-14 19:59:51 +0000
committerMark Doffman <mark.doffman@codethink.co.uk>2014-03-03 16:07:54 +0000
commit369502b0f7b90795256c241b9dbe53d94170d5ec (patch)
tree412d9bb641320a915a03eb7b3f75258b1e3e1941
parent13c711b5f980029a0cb6918521af906f3e85062a (diff)
downloadcliapp-369502b0f7b90795256c241b9dbe53d94170d5ec.tar.gz
Add option not to add automatic '--help'baserock/markdoffman/remove-automatic-help
Allow apps to have custom '--help' options by providing the ability to remove the automatic '--help' and '--help-all' generation.
-rw-r--r--cliapp/settings.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/cliapp/settings.py b/cliapp/settings.py
index b58a3e7..b2d0abb 100644
--- a/cliapp/settings.py
+++ b/cliapp/settings.py
@@ -410,7 +410,8 @@ class Settings(object):
return name
def build_parser(self, configs_only=False, arg_synopsis=None,
- cmd_synopsis=None, deferred_last=[], all_options=False):
+ cmd_synopsis=None, deferred_last=[], all_options=False,
+ add_help_option=True):
'''Build OptionParser for parsing command line.'''
# Call a callback function unless we're in configs_only mode.
@@ -440,7 +441,8 @@ class Settings(object):
formatter=FormatHelpParagraphs(),
usage=usage,
description=description,
- epilog=self.epilog)
+ epilog=self.epilog,
+ add_help_option=add_help_option)
# Create all OptionGroup objects. This way, the user code can
# add settings to built-in option groups.
@@ -555,11 +557,12 @@ class Settings(object):
sys.stdout.write(pp.format_help())
sys.exit(0)
- config_group.add_option(
- '--help-all',
- action='callback',
- help='show all options',
- callback=defer_last(maybe(help_all)))
+ if add_help_option:
+ config_group.add_option(
+ '--help-all',
+ action='callback',
+ help='show all options',
+ callback=defer_last(maybe(help_all)))
# Add other options, from the user-defined and built-in
# settingses.
@@ -623,7 +626,7 @@ class Settings(object):
def parse_args(self, args, parser=None, suppress_errors=False,
configs_only=False, arg_synopsis=None,
cmd_synopsis=None, compute_setting_values=None,
- all_options=False):
+ all_options=False, add_help_option=True):
'''Parse the command line.
Return list of non-option arguments. ``args`` would usually
@@ -637,7 +640,8 @@ class Settings(object):
arg_synopsis=arg_synopsis,
cmd_synopsis=cmd_synopsis,
deferred_last=deferred_last,
- all_options=all_options)
+ all_options=all_options,
+ add_help_option=add_help_option)
if suppress_errors:
p.error = lambda msg: sys.exit(1)