Fixed a bug with formatting for arguments
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 981172f · Browse files · 1 file·+20 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+20 added−10 removed
- other:+20 added−10 removed
Provenance
- Commit
2ca87b3- Tree
cddb940- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
981172f
1 file changed+20 added−10 removed
modified:click/core.py+20 added-10 removed
279 unmodified lines280 281 def format_usage(self, ctx):282 """Formats the usage line."""283 formatter = HelpFormatter()284- formatter.write_usage(ctx.command_path,285- self.options_metavar)284+ self._format_usage(ctx, formatter)285 return formatter.getvalue()286 287 def format_help(self, ctx):288 """Formats the help."""6 unmodified lines295 self._format_help(ctx, formatter)296 self._format_options(ctx, formatter)297 self._format_epilog(ctx, formatter)298 299+ def _collect_usage_pieces(self, ctx):300+ rv = [self.options_metavar]301+ for param in self.params:302+ rv.extend(param.get_usage_pieces(ctx))303+ return rv304+305 def _format_usage(self, ctx, formatter):301- formatter.write_usage(ctx.command_path,302- self.options_metavar)306+ pieces = self._collect_usage_pieces(ctx)307+ formatter.write_usage(ctx.command_path, ' '.join(pieces))308 formatter.write_paragraph()309 310 def _format_help(self, ctx, formatter):311 if self.help:150 unmodified lines462 parser = Command._make_parser(self, ctx)463 parser.allow_interspersed_args = False464 return parser465 461- def _format_usage(self, ctx, formatter):462- formatter.write_usage(ctx.command_path,463- self.options_metavar + ' ' +464- self.subcommand_metavar)465- formatter.write_paragraph()466+ def _collect_usage_pieces(self, ctx):467+ rv = Command._collect_usage_pieces(self, ctx)468+ rv.append(self.subcommand_metavar)469+ return rv470 471 def _format_options(self, ctx, formatter):472 Command._format_options(self, ctx, formatter)473 self._format_commands(ctx, formatter)246 unmodified lines720 721 def get_help_record(self, ctx):722 pass723 724+ def get_usage_pieces(self, ctx):725+ return []726 727+728 class Option(Parameter):729 """Options are usually optionaly values on the command line and730 have some extra features that arguments don't have.731 251 unmodified lines983 'parameter declarations, got %d' % len(decls))984 return name.replace('-', '_'), [arg], []985 986 def _add_to_parser(self, parser, ctx):980- parser.usage += ' ' + self.make_metavar()987+ pass988 989+ def get_usage_pieces(self, ctx):990+ return [self.make_metavar()]991+992 def consume_value(self, ctx, opts, args):993 found = True994 if self.nargs == 1:995 try:21 unmodified lines