Skip to content
Myr

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

5 files+31 added−16 removed

modified:click/core.py+13 added-8 removed
6 unmodified lines
7from .utils import make_str, make_default_short_help, echo8from .exceptions import ClickException, UsageError, Abort9from .termui import prompt, confirm10from .formatting import HelpFormatter11from .parser import OptionParser11from .parser import OptionParser, split_opt1213from ._compat import PY2, isidentifier1415_missing = object()
696 unmodified lines
712 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 lines
960 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))966967 rv.sort(key=lambda x: x[0])968969 rv = ', '.join(x[1] for x in rv)970 if not self.is_flag:971 rv += ' ' + self.make_metavar()972 return rv973974 rv = [_write_opts(self.opts)]975 if self.secondary_opts:976 rv.append(_write_opts(self.secondary_opts))977
102 unmodified lines
modified:click/decorators.py+1 added
175 unmodified lines
176 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 decorator183184
82 unmodified lines
modified:click/formatting.py+1 added-1 removed
188 unmodified lines
189 subsequent_indent=indent,190 preserve_paragraphs=True))191 self.write('\n')192193 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.196197 :param rows: a list of two item tuples for the terms and values.
54 unmodified lines
modified:click/parser.py+15 added-6 removed
17 unmodified lines
18from .exceptions import UsageError19from .utils import unpack_args202122def 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:]293031class Option(object):3233 def __init__(self, opts, dest, action=None, nargs=1, const=None):34 self._short_opts = []35 self._long_opts = []36 self.prefixes = set()3738 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)4950 if action is None:51 action = 'store'52
232 unmodified lines
modified:click/types.py+1 added-1 removed
62 unmodified lines
63 self.fail(value, param, ctx)646566class StringParamType(ParamType):67 name = 'string'67 name = 'text'6869 def convert(self, value, param, ctx):70 if isinstance(value, bytes):71 try:
247 unmodified lines