Make documentation invoke click and fix a bunch of issues
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 87adb71 · Browse files · 7 files·+438 added−150 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+438 added−150 removed
- other:+438 added−150 removed
Provenance
- Commit
0a44670- Tree
6b5ef7a- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
87adb71
7 files changed+438 added−150 removed
modified:docs/arguments.rst+33 added-24 removed
13 unmodified lines14 The most basic option is a simple string argument of one value. If no15 type is provided the type of the default value is used. If no default16 value is provided the type is assumed to be :data:`STRING`.17 18-Example::18+Example:19 20+.. click:example::21+22 @click.command()23 @click.argument('filename')24 def touch(filename):25 print(filename)26 25-And what it looks like::27+And what it looks like:28 27- $ python touch.py foo.txt28- foo.txt29+.. click:run::30 31+ invoke(touch, args=['foo.txt'])32+33 Variadic Arguments34 ------------------35 36 The second most common version is variadic arguments where a specific (or3 unmodified lines40 41 The value is then passed as a tuple. Note that only one argument really42 can be set to ``nargs=-1`` and right now only the last.43 41-Example::44+Example:45 46+.. click:example::47+48 @click.command()49 @click.argument('files', nargs=-1)50 def touch(files):51 for file in files:52 print(file)53 49-And what it looks like::54+And what it looks like:55 51- $ python touch.py foo.txt bar.txt52- foo.txt53- bar.txt56+.. click:run::57 58+ invoke(touch, args=['foo.txt', 'bar.txt'])59+60 .. _file-args:61 62 File Arguments63 --------------6 unmodified lines70 Click supports this through the :class:`click.File` type which71 intelligently handles files for you. It also deals with unicode and bytes72 correctly for all versions of Python so your script stays very portable.73 69-Example::74+Example:75 76+.. click:example::77+78 @click.command()79 @click.argument('input', type=click.File('rb'))80 @click.argument('output', type=click.File('wb'))81 def inout(input, output):2 unmodified lines84 if not chunk:85 break86 output.write(chunk)87 81-And what it does::88+And what it does:89 83- $ python inout.py - hello.txt84- hello85- ^D86- $ python inout.py hello.txt -87- hello90+.. click:run::91 92+ with isolated_filesystem():93+ invoke(inout, args=['-', 'hello.txt'], input=['hello'])94+ invoke(inout, args=['hello.txt', '-'])95+96 Environment Variables97 ---------------------98 99 Like options, arguments can also get values from an environment variable.100 Unlike options however this is only supported for explicitly named101 environment variables.102 96-Example usage::103+Example usage:104 105+.. click:example::106+107 @click.command()99- @click.argument('--src', envvar='SRC', type=click.File('r'))108+ @click.argument('src', envvar='SRC', type=click.File('r'))109 def echo(src):110 print(src.read())111 103- if __name__ == '__main__':104- echo()112+And from the command line:113 106-And from the command line::114+.. click:run::115 108- $ export SRC=hello.txt109- $ python echo.py110- Hello!116+ with isolated_filesystem():117+ with open('hello.txt', 'w') as f:118+ f.write('Hello World!')119+ invoke(echo, env={'SRC': 'hello.txt'})120 121 In that case it can also be a list of different environment variables122 where the first one is picked.123 2 unmodified linesadded:docs/clickdoctools.py+251 added
1+import os2+import sys3+import click4+import shutil5+import tempfile6+import contextlib7+8+try:9+ from StringIO import StringIO10+except ImportError:11+ from io import StringIO12+13+from docutils import nodes14+from docutils.statemachine import ViewList15+16+from sphinx.domains import Domain17+from sphinx.util.compat import Directive18+19+20+class EchoingStdin(object):21+22+ def __init__(self, input, output):23+ self._input = input24+ self._output = output25+26+ def __getattr__(self, x):27+ return getattr(self._input, x)28+29+ def read(self, n=-1):30+ rv = self._input.read(n)31+ self._output.write(rv)32+ return rv33+34+ def readline(self, n=-1):35+ rv = self._input.readline(n)36+ self._output.write(rv)37+ return rv38+39+ def readlines(self):40+ rv = self._input.readlines()41+ for line in rv:42+ self._output.write(rv)43+ return rv44+45+ def __iter__(self):46+ for x in self._input:47+ self._output.write(x)48+ yield x49+50+51+@contextlib.contextmanager52+def isolation(input=None, env=None):53+ if click.PY2 and isinstance(input, unicode):54+ input = input.encode('utf-8')55+ input = StringIO(input or '')56+ output = StringIO()57+ sys.stdin = EchoingStdin(input, output)58+ sys.stdin.encoding = 'utf-8'59+60+ def visible_input(prompt=None):61+ sys.stdout.write(prompt or '')62+ val = input.readline().rstrip('\r\n')63+ sys.stdout.write(val + '\n')64+ sys.stdout.flush()65+ return val66+67+ def hidden_input(prompt=None):68+ sys.stdout.write((prompt or '') + '\n')69+ sys.stdout.flush()70+ return input.readline().rstrip('\r\n')71+72+ sys.stdout = output73+ sys.stderr = output74+ old_visible_prompt_func = click.visible_prompt_func75+ old_hidden_prompt_func = click.hidden_prompt_func76+ click.visible_prompt_func = visible_input77+ click.hidden_prompt_func = hidden_input78+79+ old_env = {}80+ try:81+ if env:82+ for key, value in env.iteritems():83+ old_env[key] = os.environ.get(value)84+ os.environ[key] = value85+ yield output86+ finally:87+ for key, value in old_env.iteritems():88+ if value is None:89+ try:90+ del os.environ[key]91+ except Exception:92+ pass93+ else:94+ os.environ[key] = value95+ sys.stdout = sys.__stdout__96+ sys.stderr = sys.__stderr__97+ click.visible_prompt_func = old_visible_prompt_func98+ click.hidden_prompt_func = old_hidden_prompt_func99+100+101+@contextlib.contextmanager102+def isolated_filesystem():103+ cwd = os.getcwd()104+ t = tempfile.mkdtemp()105+ os.chdir(t)106+ try:107+ yield108+ finally:109+ os.chdir(cwd)110+ try:111+ shutil.rmtree(t)112+ except (OSError, IOError):113+ pass114+115+116+class ExampleRunner(object):117+118+ def __init__(self):119+ self.namespace = {120+ 'click': click,121+ }122+123+ def declare(self, source):124+ code = compile(source, '<docs>', 'exec')125+ eval(code, self.namespace)126+127+ def run(self, source):128+ code = compile(source, '<docs>', 'exec')129+ buffer = []130+131+ def invoke(cmd, args=None, prog_name=None, prog_prefix='python ',132+ input=None, env=None, auto_envvar_prefix=None):133+ if env:134+ for key, value in sorted(env.items()):135+ if ' ' in value:136+ value = '"%s"' % value137+ buffer.append('$ export %s=%s' % (key, value))138+ args = args or []139+ if prog_name is None:140+ prog_name = cmd.name.replace('_', '-') + '.py'141+ buffer.append(('$ %s%s %s' % (142+ prog_prefix,143+ prog_name,144+ ' '.join(('"%s"' % x) if ' ' in x else x for x in args)145+ )).rstrip())146+ if isinstance(input, (tuple, list)):147+ input = '\n'.join(input) + '\n'148+ with isolation(input=input, env=env) as output:149+ try:150+ cmd.main(args=args, prog_name=prog_name,151+ auto_envvar_prefix=auto_envvar_prefix)152+ except SystemExit:153+ pass154+ buffer.extend(output.getvalue().splitlines())155+156+ def println(text=''):157+ buffer.append(text)158+159+ eval(code, self.namespace, {160+ 'invoke': invoke,161+ 'println': println,162+ 'isolated_filesystem': isolated_filesystem,163+ })164+ return buffer165+166+ def close(self):167+ pass168+169+170+def parse_rst(state, content_offset, doc):171+ node = nodes.section()172+ # hack around title style bookkeeping173+ surrounding_title_styles = state.memo.title_styles174+ surrounding_section_level = state.memo.section_level175+ state.memo.title_styles = []176+ state.memo.section_level = 0177+ state.nested_parse(doc, content_offset, node, match_titles=1)178+ state.memo.title_styles = surrounding_title_styles179+ state.memo.section_level = surrounding_section_level180+ return node.children181+182+183+def get_example_runner(document):184+ runner = getattr(document, 'click_example_runner', None)185+ if runner is None:186+ runner = document.click_example_runner = ExampleRunner()187+ return runner188+189+190+class ExampleDirective(Directive):191+ has_content = True192+ required_arguments = 0193+ optional_arguments = 0194+ final_argument_whitespace = False195+196+ def run(self):197+ doc = ViewList()198+ runner = get_example_runner(self.state.document)199+ try:200+ runner.declare('\n'.join(self.content))201+ except:202+ runner.close()203+ raise204+ doc.append('.. sourcecode:: python', '')205+ doc.append('', '')206+ for line in self.content:207+ doc.append(' ' + line, '')208+ return parse_rst(self.state, self.content_offset, doc)209+210+211+class RunExampleDirective(Directive):212+ has_content = True213+ required_arguments = 0214+ optional_arguments = 0215+ final_argument_whitespace = False216+217+ def run(self):218+ doc = ViewList()219+ runner = get_example_runner(self.state.document)220+ try:221+ rv = runner.run('\n'.join(self.content))222+ except:223+ runner.close()224+ raise225+ doc.append('.. sourcecode:: text', '')226+ doc.append('', '')227+ for line in rv:228+ doc.append(' ' + line, '')229+ return parse_rst(self.state, self.content_offset, doc)230+231+232+class ClickDomain(Domain):233+ name = 'click'234+ label = 'Click'235+ directives = {236+ 'example': ExampleDirective,237+ 'run': RunExampleDirective,238+ }239+240+241+def delete_example_runner_state(app, doctree):242+ runner = getattr(doctree, 'click_example_runner', None)243+ if runner is not None:244+ runner.close()245+ del doctree.click_example_runner246+247+248+def setup(app):249+ app.add_domain(ClickDomain)250+251+ app.connect('doctree-read', delete_example_runner_state)modified:docs/conf.py+3 added-1 removed
16 unmodified lines17 # add these directories to sys.path here. If the directory is relative to the18 # documentation root, use os.path.abspath to make it absolute, like shown here.19 sys.path.append(os.path.abspath('_themes'))20 sys.path.append(os.path.abspath('..'))21+sys.path.append(os.path.abspath('.'))22 23 # -- General configuration -----------------------------------------------------24 25 # If your documentation needs a minimal Sphinx version, state it here.26 #needs_sphinx = '1.0'27 28 # Add any Sphinx extension module names here, as strings. They can be extensions29 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.29-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx']30+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx',31+ 'clickdoctools']32 33 # Add any paths that contain templates here, relative to this directory.34 templates_path = ['_templates']35 184 unmodified linesmodified:docs/index.rst+3 added-1 removed
13 unmodified lines14 - arbitrary nesting of commands15 - automatic help page generation16 - supports lazy loading of subcommands at runtime17 18-What does it look like? A simple example can be this::18+What does it look like? A simple example can be this:19 20+.. click:example::21+22 import click23 24 @click.command()25 @click.option('--count', default=1, help='number of greetings')44 unmodified linesmodified:docs/options.rst+114 added-99 removed
11 unmodified lines12 13 The most basic option is a value option. These options accept one14 argument which is a value. If no type is provided the type of the default15 value is used. If no default value is provided the type is assumed to be16-:data:`STRING`.16+:data:`STRING`. The name of the parameter is the longest option defined.17 18-Example::18+.. click:example::19 20 @click.command()21 @click.option('--n', default=1)22 def dots(n):23 print('.' * n)24 25-And on the command line::25+And on the command line:26 27- $ python dots.py --n=228- ..27+.. click:run::28 29+ invoke(dots, args=['--n=2'])30+31 In this case the option is of type :data:`INT` because the default value32 is an integer.33 33-The name of the parameter is the longest.34-34 Multi Value Options35 -------------------36 37 Sometimes you have options that take more than one argument. For options38 only a fixed number of arguments is supported. This can be configured by39 the ``nargs`` parameter. The values are then stored as a tuple.40 42-Example::41+.. click:example::42 44-43 @click.command()44 @click.option('--pos', nargs=2, type=float)45 def findme(pos):46 print('%s / %s' % pos)47 50-And on the command line::48+And on the command line:49 52- $ python findme.py --pos 2.0 3.053- 2.0 / 3.050+.. click:run::51 52+ invoke(findme, args=['--pos', '2.0', '3.0'])53+54 Multiple Options55 ----------------56 57 Similar to ``nargs`` there is also the case where sometimes you want to1 unmodified line59 recorded and not just the last one. For instance ``git commit -m foo -m60 bar`` would record two lines for the commit message. ``foo`` and ``bar``.61 This can be accomplished with the ``multiple`` flag:62 64-Example::63+Example:64 65+.. click:example::66+67 @click.command()68 @click.option('--message', '-m', multiple=True)69 def commit(message):70 print('\n'.join(message))71 71-And on the command line::72+And on the command line:73 73- $ python commit.py -m foo -m bar74- foo75- bar74+.. click:run::75 76+ invoke(commit, args=['-m', 'foo', '-m', 'bar'])77+78 Counting79 --------80 81 If you have used ``optparse`` or ``argparse`` before you might be missing82 support for counting. This is a very rarely useful feature, usually only83 useful for implementing verbosity flags. It can however be emulated by83-using the multiple flag and taking the length of the end result::84+using the multiple flag and taking the length of the end result:85 86+.. click:example::87+88 @click.command()89 @click.option('-v', '--verbose', is_flag=True, multiple=True)90 def log(verbose):91 verbosity = len(verbose)92 print('Verbosity: %s' % verbosity)93 91-And on the command line::94+And on the command line:95 93- $ python log.py -vvv94- Verbosity: 396+.. click:run::97 98+ invoke(log, args=['-vvv'])99+100 Boolean Flags101 -------------102 103 Boolean flags are options that can be enabled or disabled. This can be104 accomplished by defining two flags in one go separated by a slash (``/``)105 for enabling or disabling the option. Click always wants you to provide106 an enable and disable flag so that you can change the default later.107 104-Example::108+Example:109 110+.. click:example::111+112 import os113 114 @click.command()115 @click.option('--shout/--no-shout', default=False)2 unmodified lines118 if shout:119 rv = rv.upper() + '!!!!111'120 print(rv)121 116-And on the command line::122+And on the command line:123 118- $ python info.py --shout119- DARWIN!!!!111120- $ python info.py --no-shout121- Darwin124+.. click:run::125 126+ invoke(info, args=['--shout'])127+ invoke(info, args=['--no-shout'])128+129 If you really don't want an off-switch you can just define one and124-manually inform click that something is a flag::130+manually inform click that something is a flag:131 132+.. click:example::133+134 import os135 136 @click.command()137 @click.option('--shout', is_flag=True)2 unmodified lines140 if shout:141 rv = rv.upper() + '!!!!111'142 print(rv)143 136-And on the command line::144+And on the command line:145 138- $ python info.py --shout139- DARWIN!!!!111146+.. click:run::147 148+ invoke(info, args=['--shout'])149+150 Feature Switches151 ----------------152 153 In addition to boolean flags there are also feature switches. These are154 implemented by setting multiple options to the same parameter name and by155 defining a flag value. To set a default flag assign a value of `True` to156 the flag that should be the default.157 149-Example::158+.. click:example::159 160 import os161 162 @click.command()2 unmodified lines165 @click.option('--lower', 'transformation', flag_value='lower')166 def info(transformation):167 print(getattr(os.uname()[0], transformation)())168 160-And on the command line::169+And on the command line:170 162- $ python info.py --upper163- DARWIN164- $ python info.py --lower165- darwin166- $ python info.py167- DARWIN171+.. click:run::172 173+ invoke(info, args=['--upper'])174+ invoke(info, args=['--lower'])175+ invoke(info)176+177 .. _choice-opts:178 179 Choice Options180 --------------1 unmodified line182 Sometimes you want to have a parameter be a choice of a list of values.183 In that case you can use :class:`Choice` type. It can be instanciated184 with a list of valid values.185 178-Example::186+Example:187 188+.. click:example::189+190 @click.command()191 @click.option('--hash-type', type=click.Choice(['md5', 'sha1']))192 def digest(hash_type):193 print(hash_type)194 185-What it looks like::195+What it looks like:196 187- $ python digest.py --hash-type=md5188- md5197+.. click:run::198 190- $ python digest.py --hash-type=foo191- Usage: digest.py [OPTIONS]199+ invoke(digest, args=['--hash-type=md5'])200+ println()201+ invoke(digest, args=['--hash-type=foo'])202+ println()203+ invoke(digest, args=['--help'])204 193- Error: Invalid value for hash_type: invalid choice: foo. (choose from md5, sha1)194-195- $ python digest.py --help196- Usage: digest.py [OPTIONS]197-198- Options:199- --hash-type=[md5|sha1]200- --help Show this message and exit.201-205 .. _option-prompting:206 207 Prompting208 ---------1 unmodified line210 Sometimes you want parameters that can either be provided from the command211 line or if not, you want to ask for user input. This can be implemented212 with click by defining a prompt string.213 211-Example::214+Example:215 213- import os216+.. click:example::217 218 @click.command()219 @click.option('--name', prompt=True)220 def hello(name):221 print('Hello %s!' % name)222 220-And what it looks like::223+And what it looks like:224 222- $ python hello.py --name=John223- Hello John!224- $ python hello.py225- Name: John226- Hello John!225+.. click:run::226 227+ invoke(hello, args=['--name=John'])228+ invoke(hello, input=['John'])229+230 If you are not happy with the default prompt string you can ask for229-a different one::231+a different one:232 231- import os233+.. click:example::234 235 @click.command()236 @click.option('--name', prompt='Your name please')237 def hello(name):238 print('Hello %s!' % name)239 238-What it looks like::240+What it looks like:241 240- $ python hello.py241- Your name please: John242- Hello John!242+.. click:run::243 244+ invoke(hello, input=['John'])245+246 Password Prompts247 ----------------248 249 Click also supports hidden prompts and asking for confirmation. This is248-useful for password input::250+useful for password input:251 252+.. click:example::253+254 @click.command()255 @click.option('--password', prompt=True, hide_input=True,256 confirmation_prompt=True)257 def encrypt(password):258 print('Encrypting password to %s' % password.encode('rot13'))259 256-What it looks like::260+What it looks like:261 258- $ python encrypt.py259- Password:260- Repeat for confirmation:261- Encrypting password to frpher262+.. click:run::263 264+ invoke(encrypt, input=['secret', 'secret'])265+266 Because this combination of parameters is quite common this can also be264-replaced with the :func:`password_option` decorator::267+replaced with the :func:`password_option` decorator:268 269+.. click:example::270+271 @click.command()272 @click.password_option()273 def encrypt(password):274 print('Encrypting password to %s' % password.encode('rot13'))17 unmodified lines292 :class:`Context` and the value. The context provides some useful features293 such as quitting the application and gives access to other already294 processed parameters.295 291-Here an example for a ``--version`` flag::296+Here an example for a ``--version`` flag:297 298+.. click:example::299+300 def print_version(ctx, value):301 if not value:302 return303 print('Version 1.0')8 unmodified lines312 The `expose_value` parameter prevents the now pretty pointless ``version``313 parameter to be passed to the callback. If that was not specified a314 boolean would be passed to the `hello` script.315 309-What it looks like::316+What it looks like:317 311- $ python hello.py 312- Hello World!313- $ python hello.py --version314- Version 1.0318+.. click:run::319 320+ invoke(hello)321+ invoke(hello, args=['--version'])322+323 Yes Parameters324 --------------325 326 For dangerous operations it's very useful to be able to ask a user for327 confirmation. This can be done by adding a boolean ``--yes`` flag and328 asking for confirmation if the user did not provide it and to fail in a322-callback::329+callback:330 331+.. click:example::332+333 def abort_if_false(ctx, value):334 if not value:335 ctx.abort()336 3 unmodified lines340 prompt='Are you sure you want to drop the db?')341 def dropdb():342 print('Dropped all tables!')343 335-And what it looks like on the command line::344+And what it looks like on the command line:345 337- $ python dropdb.py338- Are you sure you want to drop the db? [yN]: n 339- Aborted!340- $ python dropdb.py --yes341- Dropped all tables!346+.. click:run::347 348+ invoke(dropdb, input=['n'])349+ invoke(dropdb, args=['--yes'])350+351 Because this combination of parameters is quite common this can also be344-replaced with the :func:`confirmation_option` decorator::352+replaced with the :func:`confirmation_option` decorator:353 354+.. click:example::355+356 @click.command()357 @click.confirmation_option('Are you sure you want to drop the db?')358 def dropdb():359 print('Dropped all tables!')15 unmodified lines375 underscore-separated variable in uppercase. So if you have a subcommand376 called ``foo`` taking an option called ``bar`` and the prefix is377 ``MY_TOOL`` then the variable is ``MY_TOOL_FOO_BAR``.378 369-Example usage::379+Example usage:380 381+.. click:example::382+383 @click.command()384 @click.option('--username')385 def greet(username):386 print('Hello %s!' % username)387 388 if __name__ == '__main__':389 greet(auto_envvar_prefix='GREETER')390 379-And from the command line::391+And from the command line:392 381- $ export GREETER_USERNAME=john382- $ python greet.py383- Hello john!393+.. click:run::394 395+ invoke(greet, env={'GREETER_USERNAME': 'john'},396+ auto_envvar_prefix='GREETER')397+398 The second option is to manually pull values in from specific environment399 variables by defining the name of the environment variable on the option.400 388-Example usage::401+Example usage:402 403+.. click:example::404+405 @click.command()406 @click.option('--username', envvar='USERNAME')407 def greet(username):408 print('Hello %s!' % username)409 410 if __name__ == '__main__':411 greet()412 398-And from the command line::413+And from the command line:414 400- $ export USERNAME=john401- $ python greet.py402- Hello john!415+.. click:run::416 417+ invoke(greet, env={'USERNAME': 'john'})418+419 In that case it can also be a list of different environment variables420 where the first one is picked.modified:docs/quickstart.rst+24 added-22 removed
14 unmodified lines15 for high-level usage.16 17 A function becomes a click command line tool by decorating it through18 :func:`click.command`. In the most simple version just decorating a19-function with this decorator will make it into a callable script::19+function with this decorator will make it into a callable script:20 21+.. click:example::22+23 import click24 25 @click.command()26 def hello():4 unmodified lines31 32 if __name__ == '__main__':33 hello()34 35+And what it looks like:36+37+.. click:run::38+39+ invoke(hello, args=[])40+41+And the corresponding help page:42+43+.. click:run::44+45+ invoke(hello, args=['--help'])46+47 Nesting Commands48 ----------------49 50 Commands can be attached to other commands of type :class:`Group`. This51 allows arbitrary nesting of scripts. As an example here is a script that38-implements two commands for managing databases::52+implements two commands for managing databases:53 40- import click54+.. click:example::55 56 @click.group()57 def cli():58 pass8 unmodified lines67 68 cli.add_command(initdb)69 cli.add_command(dropdb)70 57- if __name__ == '__main__':58- cli()59-71 As you can see the :func:`group` decorator works like the :func:`command`72 decorator but creates a :class:`Group` object instead which can be given73 multiple subcommands that can be attached with74 :meth:`Group.add_command`.75 76 For simple scripts it's also possible to automatically attach and create a77 command by using the :meth:`Group.command` decorator instead. The above67-script can be written like this then::78+script can be written like this then:79 69- import click80+.. click:example::81 82 @click.group()83 def cli():84 pass5 unmodified lines90 @cli.command()91 def dropdb():92 print('Dropped the database')93 83- if __name__ == '__main__':84- cli()85-94 Adding Parameters95 -----------------96 89-To add parameters the :func:`option` and :func:`argument` decorators::97+To add parameters the :func:`option` and :func:`argument` decorators:98 91- import click99+.. click:example::100 101 @click.command()102 @click.option('--count', default=1, help='number of greetings')103 @click.argument('name')104 def hello(count, name):105 for x in range(count):106 print('Hello %s!' % name)107 100- if __name__ == '__main__':101- hello()108+What it looks like:109 103-What it looks like::110+.. click:run::111 105- $ python hello.py106- Usage: hello.py [OPTIONS] NAME107-108- Options:109- --count=COUNT number of greetings110- --help Show this message and exit.112+ invoke(hello, args=['--help'])modified:click.py+10 added-3 removed
105 unmodified lines106 pass107 return wrapper108 109 110+# The prompt functions to use. The doc tools currently override these111+# functions to customize them.112+hidden_prompt_func = getpass.getpass113+visible_prompt_func = raw_input114+115+116 class TextWrapper(textwrap.TextWrapper):117 118 def _cutdown(self, ucstr, space_left):119 l = 047 unmodified lines167 if file is None:168 file = sys.stdout169 if message:170 if PY2 and isinstance(message, text_type):165- message = message.encode(file.encoding)171+ message = message.encode(getattr(file, 'encoding', None)172+ or 'utf-8', 'replace')173 file.write(message)174 file.write('\n')175 file.flush()176 1387 unmodified lines1564 """1565 prompt = '%s [%s]: ' % (text, default and 'Yn' or 'yN')1566 while 1:1567 try:1561- value = raw_input(prompt).lower().strip()1568+ value = visible_prompt_func(prompt).lower().strip()1569 except (KeyboardInterrupt, EOFError):1570 raise Abort()1571 if value in ('y', 'yes'):1572 rv = True32 unmodified lines1605 """1606 result = None1607 1608 def prompt_func(text):1602- f = hide_input and getpass.getpass or raw_input1609+ f = hide_input and hidden_prompt_func or visible_prompt_func1610 try:1611 return f(text)1612 except (KeyboardInterrupt, EOFError):1613 raise Abort()50 unmodified lines