Improved formatting of help pages slightly
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 523aaa0 · Browse files · 5 files·+31 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+31 added−16 removed
- other:+31 added−16 removed
Provenance
- Commit
5e86fcf- Tree
b26f1f3- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
523aaa0
5 files changed+31 added−16 removed
modified:click/core.py+13 added-8 removed
6 unmodified lines7 from .utils import make_str, make_default_short_help, echo8 from .exceptions import ClickException, UsageError, Abort9 from .termui import prompt, confirm10 from .formatting import HelpFormatter11-from .parser import OptionParser11+from .parser import OptionParser, split_opt12 13 from ._compat import PY2, isidentifier14 15 _missing = object()696 unmodified lines712 def make_metavar(self):713 if self.metavar is not None:714 return self.metavar715 metavar = self.type.get_metavar(self)716- if metavar is not None:717- return metavar718- metavar = self.name.upper()716+ if metavar is None:717+ metavar = self.type.name.upper()718 if self.nargs != 1:719 metavar += '...'720 return metavar721 238 unmodified lines960 def get_help_record(self, ctx):961 def _write_opts(opts):962 rv = []963 for opt in opts:965- if not self.is_flag:966- opt += ' ' + self.make_metavar()967- rv.append(opt)968- return ', '.join(rv)964+ prefix = split_opt(opt)[0]965+ rv.append((len(prefix), opt))966+967+ rv.sort(key=lambda x: x[0])968+969+ rv = ', '.join(x[1] for x in rv)970+ if not self.is_flag:971+ rv += ' ' + self.make_metavar()972+ return rv973+974 rv = [_write_opts(self.opts)]975 if self.secondary_opts:976 rv.append(_write_opts(self.secondary_opts))977 102 unmodified linesmodified:click/decorators.py+1 added
175 unmodified lines176 attrs.setdefault('is_flag', True)177 attrs.setdefault('callback', callback)178 attrs.setdefault('expose_value', False)179 attrs.setdefault('prompt', 'Do you want to continue?')180+ attrs.setdefault('help', 'Confirm the action without prompting.')181 return option(*(param_decls or ('--yes',)), **attrs)(f)182 return decorator183 184 82 unmodified linesmodified:click/formatting.py+1 added-1 removed
188 unmodified lines189 subsequent_indent=indent,190 preserve_paragraphs=True))191 self.write('\n')192 193- def write_dl(self, rows, col_max=20, col_spacing=2):193+ def write_dl(self, rows, col_max=30, col_spacing=2):194 """Writes a definition list into the buffer. This is how options195 and commands are usually formatted.196 197 :param rows: a list of two item tuples for the terms and values.54 unmodified linesmodified:click/parser.py+15 added-6 removed
17 unmodified lines18 from .exceptions import UsageError19 from .utils import unpack_args20 21 22+def split_opt(opt):23+ first = opt[:1]24+ if first.isalnum():25+ return '', opt26+ if opt[1:2] == first:27+ return opt[:2], opt[2:]28+ return first, opt[1:]29+30+31 class Option(object):32 33 def __init__(self, opts, dest, action=None, nargs=1, const=None):34 self._short_opts = []35 self._long_opts = []36 self.prefixes = set()37 38 for opt in opts:30- first = opt[:1]31- if first.isalnum():39+ prefix = split_opt(opt)[0]40+ if not prefix:41 raise ValueError('Invalid start character for option (%s)'33- % first)34- self.prefixes.add(first)35- if opt[1:2] != first:42+ % opt)43+ self.prefixes.add(prefix[0])44+ if len(prefix) == 1:45 self._short_opts.append(opt)46 else:47 self._long_opts.append(opt)39- self.prefixes.add(opt[:2])48+ self.prefixes.add(prefix)49 50 if action is None:51 action = 'store'52 232 unmodified linesmodified:click/types.py+1 added-1 removed
62 unmodified lines63 self.fail(value, param, ctx)64 65 66 class StringParamType(ParamType):67- name = 'string'67+ name = 'text'68 69 def convert(self, value, param, ctx):70 if isinstance(value, bytes):71 try:247 unmodified lines