From f4b503b036f76c23c4f2cb99ca6596823b323035 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Fri, 21 Feb 2014 20:39:06 +0000 Subject: Revert "Make '--help' and help subcommand the same." This reverts commit a72c8dca6965d1ac239e4f0102f08fbf7fe59ac7. --- morphlib/app.py | 69 +++++++++++++-------------------------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) (limited to 'morphlib/app.py') diff --git a/morphlib/app.py b/morphlib/app.py index acc7aa16..7fb71c7b 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -59,12 +59,6 @@ class Morph(cliapp.Application): self.settings.boolean(['quiet', 'q'], 'show no output unless there is an error') - self.settings.boolean(['help', 'h'], - 'show this help message and exit') - - self.settings.boolean(['help-all'], - 'show help message including hidden subcommands') - self.settings.string(['build-ref-prefix'], 'Prefix to use for temporary build refs', metavar='PREFIX', @@ -201,14 +195,6 @@ class Morph(cliapp.Application): def process_args(self, args): self.check_time() - if self.settings['help']: - self.help(args) - sys.exit(0) - - if self.settings['help-all']: - self.help_all(args) - sys.exit(0) - if self.settings['build-ref-prefix'] is None: if self.settings['trove-id']: self.settings['build-ref-prefix'] = os.path.join( @@ -257,7 +243,6 @@ class Morph(cliapp.Application): cliapp.Application.process_args(self, args) - def setup_plugin_manager(self): cliapp.Application.setup_plugin_manager(self) @@ -466,49 +451,27 @@ class Morph(cliapp.Application): # run the command line return cliapp.Application.runcmd(self, argv, *args, **kwargs) - def parse_args(self, args, configs_only=False): - return self.settings.parse_args(args, - configs_only=configs_only, - arg_synopsis=self.arg_synopsis, - cmd_synopsis=self.cmd_synopsis, - compute_setting_values=self.compute_setting_values, - add_help_option=False) - - class IdentityFormat(): - def format(self, text): - return text - - def _help_helper(self, args, show_all): + # FIXME: This overrides a private method in cliapp. We need + # get cliapp to provide the necessary hooks to do this cleanly. + # As it is, this is a copy of the method in cliapp, with the + # single change that for subcommand helps, the formatting is + # not used. + def _help_helper(self, args, show_all): # pragma: no cover try: width = int(os.environ.get('COLUMNS', '78')) except ValueError: width = 78 + fmt = cliapp.TextFormat(width=width) + if args: - cmd = args[0] - if cmd not in self.subcommands: - raise cliapp.AppException('Unknown subcommand %s' % cmd) - # TODO Search for other things we might want help on - # such as write or configuration extensions. - usage = self._format_usage_for(cmd) - fmt = self.IdentityFormat() - description = fmt.format(self._format_subcommand_help(cmd)) + usage = self._format_usage_for(args[0]) + description = self._format_subcommand_help(args[0]) text = '%s\n\n%s' % (usage, description) - self.output.write(text) else: - pp = self.settings.build_parser( - configs_only=True, - arg_synopsis=self.arg_synopsis, - cmd_synopsis=self.cmd_synopsis, - all_options=show_all, - add_help_option=False) - text = pp.format_help() - self.output.write(text) - - def help(self, args): # pragma: no cover - '''Print help.''' - self._help_helper(args, False) - - def help_all(self, args): # pragma: no cover - '''Print help, including hidden subcommands.''' - self._help_helper(args, True) + usage = self._format_usage(all=show_all) + description = fmt.format(self._format_description(all=show_all)) + text = '%s\n\n%s' % (usage, description) + + text = self.settings.progname.join(text.split('%prog')) + self.output.write(text) -- cgit v1.2.1