change file extension from .rst to .md
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by denuoweb · committed by denuoweb · parent 338fa44 · Browse files · 2 files·+84 added−84 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+84 added−84 removed
- other:+84 added−84 removed
Provenance
- Commit
5f2a62f- Tree
9d26a68- Author
denuoweb <jaron@rosenau.info>- Committer
denuoweb <jaron@rosenau.info>- Parent
338fa44
2 files changed+84 added−84 removed
added:docs/option-decorators.md+84 added
1+Options Shortcut Decorators2+===========================3+4+.. currentmodule:: click5+6+For convenience commonly used combinations of options arguments are available as their own decorators.7+8+.. contents::9+ :depth: 210+ :local:11+12+Password Option13+------------------14+15+Click supports hidden prompts and asking for confirmation. This is16+useful for password input:17+18+.. click:example::19+20+ import codecs21+22+ @click.command()23+ @click.option(24+ "--password", prompt=True, hide_input=True,25+ confirmation_prompt=True26+ )27+ def encode(password):28+ click.echo(f"encoded: {codecs.encode(password, 'rot13')}")29+30+.. click:run::31+32+ invoke(encode, input=['secret', 'secret'])33+34+Because this combination of parameters is quite common, this can also be35+replaced with the :func:`password_option` decorator:36+37+.. code-block:: python38+39+ @click.command()40+ @click.password_option()41+ def encrypt(password):42+ click.echo(f"encoded: to {codecs.encode(password, 'rot13')}")43+44+Confirmation Option45+--------------------46+47+For dangerous operations, it's very useful to be able to ask a user for48+confirmation. This can be done by adding a boolean ``--yes`` flag and49+asking for confirmation if the user did not provide it and to fail in a50+callback:51+52+.. click:example::53+54+ def abort_if_false(ctx, param, value):55+ if not value:56+ ctx.abort()57+58+ @click.command()59+ @click.option('--yes', is_flag=True, callback=abort_if_false,60+ expose_value=False,61+ prompt='Are you sure you want to drop the db?')62+ def dropdb():63+ click.echo('Dropped all tables!')64+65+And what it looks like on the command line:66+67+.. click:run::68+69+ invoke(dropdb, input=['n'])70+ invoke(dropdb, args=['--yes'])71+72+Because this combination of parameters is quite common, this can also be73+replaced with the :func:`confirmation_option` decorator:74+75+.. click:example::76+77+ @click.command()78+ @click.confirmation_option(prompt='Are you sure you want to drop the db?')79+ def dropdb():80+ click.echo('Dropped all tables!')81+82+Version Option83+----------------84+:func:`version_option` adds a ``--version`` option which immediately prints the version number and exits the program.deleted:docs/option-decorators.rst-84 removed
1-Options Shortcut Decorators2-===========================3-4-.. currentmodule:: click5-6-For convenience commonly used combinations of options arguments are available as their own decorators.7-8-.. contents::9- :depth: 210- :local:11-12-Password Option13-------------------14-15-Click supports hidden prompts and asking for confirmation. This is16-useful for password input:17-18-.. click:example::19-20- import codecs21-22- @click.command()23- @click.option(24- "--password", prompt=True, hide_input=True,25- confirmation_prompt=True26- )27- def encode(password):28- click.echo(f"encoded: {codecs.encode(password, 'rot13')}")29-30-.. click:run::31-32- invoke(encode, input=['secret', 'secret'])33-34-Because this combination of parameters is quite common, this can also be35-replaced with the :func:`password_option` decorator:36-37-.. code-block:: python38-39- @click.command()40- @click.password_option()41- def encrypt(password):42- click.echo(f"encoded: to {codecs.encode(password, 'rot13')}")43-44-Confirmation Option45---------------------46-47-For dangerous operations, it's very useful to be able to ask a user for48-confirmation. This can be done by adding a boolean ``--yes`` flag and49-asking for confirmation if the user did not provide it and to fail in a50-callback:51-52-.. click:example::53-54- def abort_if_false(ctx, param, value):55- if not value:56- ctx.abort()57-58- @click.command()59- @click.option('--yes', is_flag=True, callback=abort_if_false,60- expose_value=False,61- prompt='Are you sure you want to drop the db?')62- def dropdb():63- click.echo('Dropped all tables!')64-65-And what it looks like on the command line:66-67-.. click:run::68-69- invoke(dropdb, input=['n'])70- invoke(dropdb, args=['--yes'])71-72-Because this combination of parameters is quite common, this can also be73-replaced with the :func:`confirmation_option` decorator:74-75-.. click:example::76-77- @click.command()78- @click.confirmation_option(prompt='Are you sure you want to drop the db?')79- def dropdb():80- click.echo('Dropped all tables!')81-82-Version Option83-----------------84-:func:`version_option` adds a ``--version`` option which immediately prints the version number and exits the program.