-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC add basic example with CommandCollection
- Loading branch information
1 parent
9f725e5
commit b6a0508
Showing
9 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.. _example_commandcollections: | ||
|
||
Documentating |CommandCollection| | ||
================================= | ||
|
||
The client in the file ``examples/commandcollections/cli.py`` using a | ||
|CommandCollection| such as | ||
|
||
.. literalinclude:: ../../examples/commandcollections/cli.py | ||
|
||
The automatic documentation using *sphinx-click* gives for the following directive: | ||
|
||
.. code-block:: rst | ||
.. click:: commandcollections.cli:cli | ||
:prog: cli | ||
:nested: full | ||
---- | ||
|
||
.. click:: commandcollections.cli:cli | ||
:prog: cli | ||
:nested: full | ||
|
||
|
||
.. |CommandCollection| replace:: ``CommandCollection`` | ||
.. _CommandCollection: https://click.palletsprojects.com/en/7.x/api/#click.CommandCollection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Examples | ||
======== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
|
||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ __ http://click.pocoo.org/ | |
usage | ||
contributing | ||
changelog | ||
examples/index | ||
|
||
.. seealso:: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# file: cli.py | ||
import click | ||
|
||
|
||
main = click.Group( | ||
name='Principal Commands', | ||
help="Principal commands that are used in ``cli``.\n\n" | ||
"The section name and description are obtained using the name and " | ||
"description of the group passed as sources for |CommandCollection|_." | ||
) | ||
|
||
|
||
@main.command(help='CMD 1') | ||
def cmd1(): | ||
print('call cmd 1') | ||
|
||
|
||
helpers = click.Group( | ||
name='Helper Commands', | ||
help="Helper commands for ``cli``." | ||
) | ||
|
||
|
||
@helpers.command() | ||
def cmd2(): | ||
"Helper command that has no option." | ||
pass | ||
|
||
|
||
@helpers.command() | ||
@click.option('--user', type=str) | ||
def cmd3(user): | ||
"Helper command with an option." | ||
pass | ||
|
||
|
||
cli = click.CommandCollection( | ||
name='cli', sources=[main, helpers], | ||
help='Some general info on ``cli``.' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name='sphinx_click_examples', | ||
packages=find_packages('.'), | ||
install_requires=['click'] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters