summaryrefslogtreecommitdiff
path: root/docs/options.rst
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2015-03-31 16:48:44 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2015-03-31 16:48:44 +0200
commitf7c124ed82ee1307bf61be652367d8fc8097e4ed (patch)
treea1ecb9abfcaf5c42c55798948ea5db40ce8f184f /docs/options.rst
parentdd0635c33cc4566ccb2e3cfb6fbf203bbcd1dd5a (diff)
downloadclick-f7c124ed82ee1307bf61be652367d8fc8097e4ed.tar.gz
Added support for tuple types. This fixes #239
Diffstat (limited to 'docs/options.rst')
-rw-r--r--docs/options.rst36
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/options.rst b/docs/options.rst
index f399c44..73fc8ca 100644
--- a/docs/options.rst
+++ b/docs/options.rst
@@ -55,6 +55,42 @@ And on the command line:
invoke(findme, args=['--pos', '2.0', '3.0'])
+.. _tuple-type:
+
+Tuples as Multi Value Options
+-----------------------------
+
+.. versionadded:: 4.0
+
+As you can see that by using `nargs` set to a specific number each item in
+the resulting tuple is of the same type. This might not be what you want.
+Commonly you might want to use different types for different indexes in
+the tuple. For this you can directly specify a tuple as type:
+
+.. click:example::
+
+ @click.command()
+ @click.option('--item', type=(unicode, int))
+ def putitem(item):
+ click.echo('name=%s id=%d' % item)
+
+And on the command line:
+
+.. click:run::
+
+ invoke(putitem, args=['--item', 'peter', '1338'])
+
+By using a tuple literal as type, `nargs` gets automatically set to the
+length of the tuple and the :class:`click.Tuple` type is automatically
+used. The above example is thus equivalent to this:
+
+.. click:example::
+
+ @click.command()
+ @click.option('--item', nargs=2, type=click.Tuple([unicode, int]))
+ def putitem(item):
+ click.echo('name=%s id=%d' % item)
+
Multiple Options
----------------