Some small fixes for problems
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent ded4bd5 · Browse files · 3 files·+12 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+12 added−6 removed
- other:+12 added−6 removed
Provenance
- Commit
8f7caca- Tree
07391ae- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
ded4bd5
3 files changed+12 added−6 removed
modified:click/_optparse.py+4 added-1 removed
7 unmodified lines8 # In case someone does depend on gettext being loaded into optparse we9 # might have a problem but I don't think anyone will actually notice.10 _gettext = sys.modules.get('gettext')11 sys.modules['gettext'] = None12-from optparse import IndentedHelpFormatter, OptionParser, Option12+from optparse import IndentedHelpFormatter, OptionParser, Option, \13+ SUPPRESS_HELP14 if _gettext is not None:15 sys.modules['gettext'] = _gettext16 else:17 del sys.modules['gettext']68 unmodified lines86 def error(self, msg):87 raise UsageError(msg, self.__ctx)88 89 90+# Re-exports91 make_option = Option92+SUPPRESS_HELP = SUPPRESS_HELPmodified:click/core.py+7 added-4 removed
352 unmodified lines353 parser.disable_interspersed_args()354 return parser355 356 def _format_extra_help(self, ctx):357- commands = self.list_commands()357+ commands = self.list_commands(ctx)358 if not commands:359 return360 361 longest = len(sorted(commands, key=len)[-1])362 363 subcommand_info = []364- for subcommand in self.list_commands():364+ for subcommand in self.list_commands(ctx):365 cmd = self.get_command(ctx, subcommand)366+ # What is this, the tool lied about a command. Ignore it367+ if cmd is None:368+ continue369 help = cmd.short_help or ''370 subcommand_info.append(' %-*s %s' % (longest, subcommand, help))371 372 return 'Commands:\n%s' % '\n'.join(subcommand_info)29 unmodified lines402 :class:`Command` object if it exists or returns `None`.403 """404 raise NotImplementedError()405 403- def list_commands(self):406+ def list_commands(self, ctx):407 """Returns a list of subcommand names in the order they should408 appear.409 """410 return []34 unmodified lines445 446 def get_command(self, ctx, cmd_name):447 return self.commands.get(cmd_name)448 446- def list_commands(self):449+ def list_commands(self, ctx):450 return sorted(self.commands)451 452 453 class Parameter(object):399 unmodified linesmodified:docs/commands.rst+1 added-1 removed
174 unmodified lines175 plugin_folder = os.path.join(os.path.dirname(__file__), 'commands')176 177 class MyCLI(click.MultiCommand):178 179- def list_commands(self):179+ def list_commands(self, ctx):180 rv = []181 for filename in os.listdir(plugin_folder):182 if filename.endswith('.py'):183 rv.append(filename[:-3])24 unmodified lines