summaryrefslogtreecommitdiff
path: root/docs/commands.rst
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2014-04-29 22:07:15 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2014-04-29 22:07:15 +0200
commit055a8e6054700951c95aac3d9709e4538ec7c0b8 (patch)
treea3cc3a2a9e4a6ce5022201439c4b8ad5dc54e10a /docs/commands.rst
parent51ebc82f828d392cb5b56ed202f60855ffb12733 (diff)
downloadclick-055a8e6054700951c95aac3d9709e4538ec7c0b8.tar.gz
Implemented basic command collections
Diffstat (limited to 'docs/commands.rst')
-rw-r--r--docs/commands.rst49
1 files changed, 49 insertions, 0 deletions
diff --git a/docs/commands.rst b/docs/commands.rst
index ec3a5b5..23427cf 100644
--- a/docs/commands.rst
+++ b/docs/commands.rst
@@ -205,3 +205,52 @@ These custom classes can also be used with decorators:
@click.command(cls=MyCLI)
def cli():
pass
+
+Merging Multi Commands
+----------------------
+
+In addition to implementing custom multi commands it can also be
+interesting to merge multiple together into one script. While this is
+generally not as recommended as nesting one below the other the merging
+approach can be useful in some circumstances for a nicer shell experience.
+
+A default implementation for such a merging system is the
+:class:`CommandCollection` class. It accepts a list of other multi
+commands and makes the commands available on the same class class. It
+accepts a list of other multi commands and makes the commands available on
+the same level.
+
+Example usage:
+
+.. click:example::
+
+ import click
+
+ @click.group()
+ def cli1():
+ pass
+
+ @cli1.command()
+ def cmd1():
+ """Command on cli1"""
+
+ @click.group()
+ def cli2():
+ pass
+
+ @cli1.command()
+ def cmd2():
+ """Command on cli2"""
+
+ cli = click.CommandCollection(sources=[cli1, cli2])
+
+ if __name__ == '__main__':
+ cli()
+
+And what it looks like:
+
+.. click:run::
+
+ invoke(cli, prog_name='cli', args=['--help'])
+
+In case a command exists on more than one source, the first source wins.