Skip to content
Myr

Merge branch '7.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents 7d11997, 68c9328 · Browse files · 9 files+109 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+109 added−24 removed

  • other:+109 added−24 removed

9 files+109 added−24 removed

modified:click/_winconsole.py+3 added-3 removed
22 unmodified lines
23 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer24 PyBuffer_Release = pythonapi.PyBuffer_Release25except ImportError:26 pythonapi = None27from ctypes.wintypes import LPWSTR, LPCWSTR27from ctypes.wintypes import LPWSTR, LPCWSTR, HANDLE282930c_ssize_p = POINTER(c_ssize_t)31
90 unmodified lines
122 buffer = get_buffer(b, writable=True)123 code_units_to_be_read = bytes_to_be_read // 2124 code_units_read = c_ulong()125126 rv = ReadConsoleW(self.handle, buffer, code_units_to_be_read,126 rv = ReadConsoleW(HANDLE(self.handle), buffer, code_units_to_be_read,127 byref(code_units_read), None)128 if GetLastError() == ERROR_OPERATION_ABORTED:129 # wait for KeyboardInterrupt130 time.sleep(0.1)
24 unmodified lines
155 code_units_to_be_written = min(bytes_to_be_written,156 MAX_BYTES_WRITTEN) // 2157 code_units_written = c_ulong()158159 WriteConsoleW(self.handle, buf, code_units_to_be_written,159 WriteConsoleW(HANDLE(self.handle), buf, code_units_to_be_written,160 byref(code_units_written), None)161 bytes_written = 2 * code_units_written.value162163 if bytes_written == 0 and bytes_to_be_written > 0:
144 unmodified lines
modified:click/core.py+14 added-4 removed
890 unmodified lines
891 def __repr__(self):892 return '<%s %s>' % (self.__class__.__name__, self.name)893894 def get_usage(self, ctx):895 """Formats the usage line into a string and returns it.896897 Calls :meth:`format_usage` internally.898 """899 formatter = ctx.make_formatter()900 self.format_usage(ctx, formatter)901 return formatter.getvalue().rstrip('\n')902
4 unmodified lines
907 rv = rv + [help_option]908 return rv909910 def format_usage(self, ctx, formatter):907 """Writes the usage line into the formatter."""911 """Writes the usage line into the formatter.912913 This is a low-level method called by :meth:`get_usage`.914 """915 pieces = self.collect_usage_pieces(ctx)916 formatter.write_usage(ctx.command_path, ' '.join(pieces))917918 def collect_usage_pieces(self, ctx):
35 unmodified lines
954 param.add_to_parser(parser, ctx)955 return parser956957 def get_help(self, ctx):951 """Formats the help into a string and returns it. This creates a952 formatter and will call into the following formatting methods:958 """Formats the help into a string and returns it.959960 Calls :meth:`format_help` internally.961 """962 formatter = ctx.make_formatter()963 self.format_help(ctx, formatter)964 return formatter.getvalue().rstrip('\n')
4 unmodified lines
969970 def format_help(self, ctx, formatter):971 """Writes the help into the formatter if it exists.972965 This calls into the following methods:973 This is a low-level method called by :meth:`get_help`.974975 This calls the following methods:976977 - :meth:`format_usage`978 - :meth:`format_help_text`979 - :meth:`format_options`980 - :meth:`format_epilog`
975 unmodified lines
modified:docs/advanced.rst+5 added-3 removed
10 unmodified lines
1112Command Aliases13---------------1415Many tools support aliases for commands. For instance, you can configure16``git`` to accept ``git ci`` as alias for ``git commit``. Other tools17also support auto-discovery for aliases by automatically shortening them.15Many tools support aliases for commands (see `Command alias example16<https://github.com/pallets/click/tree/master/examples/aliases>`_).17For instance, you can configure ``git`` to accept ``git ci`` as alias for18``git commit``. Other tools also support auto-discovery for aliases by19automatically shortening them.2021Click does not support this out of the box, but it's very easy to customize22the :class:`Group` or any other :class:`MultiCommand` to provide this23functionality.
385 unmodified lines
modified:docs/arguments.rst+12 added-5 removed
6 unmodified lines
78Arguments work similarly to :ref:`options <options>` but are positional.9They also only support a subset of the features of options due to their10syntactical nature. Click will also not attempt to document arguments for11you and wants you to document them manually in order to avoid ugly help12pages.11you and wants you to :ref:`document them manually <documenting-arguments>`12in order to avoid ugly help pages.1314Basic Arguments15---------------16
7 unmodified lines
2425 @click.command()26 @click.argument('filename')27 def touch(filename):28 """Print FILENAME."""29 click.echo(filename)3031And what it looks like:32
19 unmodified lines
52 @click.command()53 @click.argument('src', nargs=-1)54 @click.argument('dst', nargs=1)55 def copy(src, dst):56 """Move file SRC to DST."""57 for fn in src:58 click.echo('move %s to folder %s' % (fn, dst))5960And what it looks like:
41 unmodified lines
102 @click.command()103 @click.argument('input', type=click.File('rb'))104 @click.argument('output', type=click.File('wb'))105 def inout(input, output):106 """Copy contents of INPUT to OUTPUT."""107 while True:108 chunk = input.read(1024)109 if not chunk:110 break
27 unmodified lines
138139.. click:example::140141 @click.command()139 @click.argument('f', type=click.Path(exists=True))140 def touch(f):141 click.echo(click.format_filename(f))142 @click.argument('filename', type=click.Path(exists=True))143 def touch(filename):144 """Print FILENAME if the file exists."""145 click.echo(click.format_filename(filename))146147And what it does:148149.. click:run::
52 unmodified lines
202203 @click.command()204 @click.argument('src', envvar='SRC', type=click.File('r'))205 def echo(src):206 """Print value of SRC environment variable."""207 click.echo(src.read())208209And from the command line:210
28 unmodified lines
239240 @click.command()241 @click.argument('files', nargs=-1, type=click.Path())242 def touch(files):243 """Print all FILES file names."""244 for filename in files:245 click.echo(filename)246247And from the command line:
9 unmodified lines
257258 @click.command(context_settings={"ignore_unknown_options": True})259 @click.argument('files', nargs=-1, type=click.Path())260 def touch(files):261 """Print all FILES file names."""262 for filename in files:263 click.echo(filename)264265And from the command line:
5 unmodified lines
modified:docs/documentation.rst+48 added-4 removed
30 unmodified lines
31.. click:run::3233 invoke(hello, args=['--help'])3435Arguments cannot be documented this way. This is to follow the general36convention of Unix tools of using arguments for only the most necessary37things and to document them in the introduction text by referring to them38by name.3536.. _documenting-arguments:3738Documenting Arguments39~~~~~~~~~~~~~~~~~~~~~4041:func:`click.argument` does not take a ``help`` parameter. This is to42follow the general convention of Unix tools of using arguments for only43the most necessary things, and to document them in the command help text44by referring to them by name.4546You might prefer to reference the argument in the description:4748.. click:example::4950 @click.command()51 @click.argument('filename')52 def touch(filename):53 """Print FILENAME."""54 click.echo(filename)5556And what it looks like:5758.. click:run::5960 invoke(touch, args=['--help'])6162Or you might prefer to explicitly provide a description of the argument:6364.. click:example::6566 @click.command()67 @click.argument('filename')68 def touch(filename):69 """Print FILENAME.7071 FILENAME is the name of the file to check.72 """73 click.echo(filename)7475And what it looks like:7677.. click:run::7879 invoke(touch, args=['--help'])8081For more examples, see the examples in :doc:`/arguments`.828384Preventing Rewrapping85---------------------8687The default behavior of Click is to rewrap text based on the width of the
154 unmodified lines
modified:docs/parameters.rst+2 added-2 removed
21 unmodified lines
22* automatic prompting for missing input23* act as flags (boolean or otherwise)24* option values can be pulled from environment variables, arguments can not25* options are fully documented in the help page, arguments are not26 (this is intentional as arguments might be too specific to be27 automatically documented)26 (:ref:`this is intentional <documenting-arguments>` as arguments27 might be too specific to be automatically documented)2829On the other hand arguments, unlike options, can accept an arbitrary number30of arguments. Options can strictly ever only accept a fixed number of31arguments (defaults to 1).
118 unmodified lines
modified:docs/python3.rst-3 removed
6 unmodified lines
7it suffers from the Unicode text model in Python 3. All examples in the8documentation were written so that they could run on both Python 2.x and9Python 3.4 or higher.1011At the moment, it is strongly recommended to use Python 2 for Click12utilities unless Python 3 is a hard requirement.1311.. _python3-limitations:1213Python 3 Limitations14--------------------
171 unmodified lines
modified:examples/aliases/aliases.py+24 added
12 unmodified lines
13 def __init__(self):14 self.path = os.getcwd()15 self.aliases = {}1617 def add_alias(self, alias, cmd):18 self.aliases.update({alias: cmd})1920 def read_config(self, filename):21 parser = configparser.RawConfigParser()22 parser.read([filename])23 try:24 self.aliases.update(parser.items('aliases'))25 except configparser.NoSectionError:26 pass2728 def write_config(self, filename):29 parser = configparser.RawConfigParser()30 parser.add_section('aliases')31 for key, value in self.aliases.items():32 parser.set('aliases', key, value)33 with open(filename, 'wb') as file:34 parser.write(file)353637pass_config = click.make_pass_decorator(Config, ensure=True)383940class AliasedGroup(click.Group):
78 unmodified lines
119@pass_config120def status(config):121 """Shows the status."""122 click.echo('Status for %s' % config.path)123124125@cli.command()126@pass_config127@click.argument("alias_", metavar='ALIAS', type=click.STRING)128@click.argument("cmd", type=click.STRING)129@click.option('--config_file', type=click.Path(exists=True, dir_okay=False),130 default="aliases.ini")131def alias(config, alias_, cmd, config_file):132 """Adds an alias to the specified configuration file."""133 config.add_alias(alias_, cmd)134 config.write_config(config_file)135 click.echo('Added %s as alias for %s' % (alias_, cmd))
modified:CHANGES.rst+1 added
29 unmodified lines
30- Fix link in ``unicode_literals`` error message. (`#1151`_)31- Add support for colored output on UNIX Jupyter notebooks. (`#1185`_)32- Remove unused compat shim for ``bytes``. (`#1195`_)33- Expand unit testing around termui, especially getchar (Windows). (`#1116`_)34- Fix output on Windows Python 2.7 built with MSVC 14. #13423536.. _#1167: https://github.com/pallets/click/pull/116737.. _#1151: https://github.com/pallets/click/pull/115138.. _#1185: https://github.com/pallets/click/issues/1185
634 unmodified lines