From 0ea37f35c47b7129b9a81e442c2d7739c6868705 Mon Sep 17 00:00:00 2001 From: Mark Doffman Date: Fri, 21 Feb 2014 20:37:58 +0000 Subject: Revert "Add write and configuration extensions to help." This reverts commit 329b81419be20e7b1f2651a47030186216044eec. --- morphlib/app.py | 89 ++++++++++++++++++++++++--------------------------------- 1 file changed, 38 insertions(+), 51 deletions(-) diff --git a/morphlib/app.py b/morphlib/app.py index 93c65c0c..acc7aa16 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -22,7 +22,6 @@ import sys import time import urlparse import warnings -import extensions import morphlib @@ -61,9 +60,10 @@ class Morph(cliapp.Application): 'show no output unless there is an error') self.settings.boolean(['help', 'h'], - 'show this help message and exit') + 'show this help message and exit') + self.settings.boolean(['help-all'], - 'show help message including hidden subcommands') + 'show help message including hidden subcommands') self.settings.string(['build-ref-prefix'], 'Prefix to use for temporary build refs', @@ -198,8 +198,6 @@ class Morph(cliapp.Application): def setup(self): self.status_prefix = '' - self.add_subcommand('help-extensions', self.help_extensions) - def process_args(self, args): self.check_time() @@ -470,58 +468,47 @@ class Morph(cliapp.Application): 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) - - def _help(self, show_all): - 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_topic(self, topic): - build_ref_prefix = self.settings['build-ref-prefix'] - if topic in self.subcommands: - usage = self._format_usage_for(topic) - description = self._format_subcommand_help(topic) + 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): + try: + width = int(os.environ.get('COLUMNS', '78')) + except ValueError: + width = 78 + + 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)) text = '%s\n\n%s' % (usage, description) self.output.write(text) - elif topic in extensions.list_extensions(build_ref_prefix): - name, kind = os.path.splitext(topic) - with extensions.get_extension_filename(build_ref_prefix, - name, - kind) as fname: - status, output, error = \ - self.runcmd_unchecked([fname, '--help']) - if status == 0 and output: - self.output.write(output) - else: - raise cliapp.AppException( - 'Help not available for extension %s' % topic) else: - raise cliapp.AppException( - 'Unknown subcommand or extension %s' % topic) + 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.''' - if args: - self._help_topic(args[0]) - else: - self._help(False) + self._help_helper(args, False) def help_all(self, args): # pragma: no cover '''Print help, including hidden subcommands.''' - self._help(True) - - def help_extensions(self, args): - exts = extensions.list_extensions(self.settings['build-ref-prefix']) - template = "Extensions:\n %s\n" - ext_string = '\n '.join(exts) - self.output.write(template % (ext_string)) + self._help_helper(args, True) -- cgit v1.2.1