Questions tagged [python-click]

Click is a Python library for creating beautiful command line interfaces.

Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It is the "Command Line Interface Creation Kit". It is highly configurable but comes with sensible defaults out of the box.

Click supports:

  • arbitrary nesting of commands
  • automatic help page generation
  • lazy loading of sub-commands at runtime

Links

363 questions
92
votes
7 answers

How can I split my Click commands, each with a set of sub-commands, into multiple files?

I have one large click application that I've developed, but navigating through the different commands/subcommands is getting rough. How do I organize my commands into separate files? Is it possible to organize commands and their subcommands into…
Brad T
  • 1,233
  • 1
  • 10
  • 12
42
votes
3 answers

Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment

I downloaded Quokka Python/Flask CMS to a CentOS7 server. Everything works fine with command sudo python3 manage.py runserver --host 0.0.0.0 --port 80 Then I create a file /etc/init.d/quokkacms. The file contains following code start() { …
Dustin Sun
  • 4,298
  • 5
  • 41
  • 76
37
votes
3 answers

Call another click command from a click command

I want to use some useful functions as commands. For that I am testing the click library. I defined my three original functions then decorated as click.command: import click import os, sys @click.command() @click.argument('content',…
kaligne
  • 2,408
  • 4
  • 29
  • 52
32
votes
3 answers

Mutually exclusive option groups in python Click

How can I create a mutually exclusive option group in Click? I want to either accept the flag "--all" or take an option with a parameter like "--color red".
b-jazz
  • 700
  • 6
  • 16
28
votes
5 answers

Why does my use of click.argument produce "got an unexpected keyword argument 'help'?

Running the following code results in this error: TypeError: init() got an unexpected keyword argument 'help' Code: import click @click.command() @click.argument('command', required=1,…
Chris Betti
  • 2,374
  • 1
  • 24
  • 36
26
votes
2 answers

Using Boolean Flags in Python Click Library (command line arguments)

I'm trying to make a verbose flag for my Python program. Currently, I'm doing this: import click #global variable verboseFlag = False #parse arguments @click.command() @click.option('--verbose', '-v', is_flag=True, help="Print more output.") def…
Hackerman
  • 753
  • 1
  • 8
  • 20
26
votes
2 answers

Click and pylint

Here is a simple example of click usage that causes pylint error: @click.command() @click.option('--option', is_flag=True) def foo(option): click.echo(option) foo() foo receives no arguments so I'm getting E1120 (no-value-for-parameter). So I…
dodd0ro
  • 387
  • 3
  • 11
25
votes
3 answers

Click Command Line Interfaces: Make options required if other optional option is unset

When writing a command-line interface (CLI) with the Python click library, is it possible to define e.g. three options where the second and third one are only required if the first (optional) one was left unset? My use case is a log-in system which…
Dirk
  • 7,235
  • 15
  • 56
  • 86
23
votes
5 answers

How to pass several list of arguments to @click.option

I want to call a python script through the command line with this kind of parameter (list could be any size, eg with 3): python test.py --option1 ["o11", "o12", "o13"] --option2 ["o21", "o22", "o23"] using click. From the docs, it is not stated…
downstroy
  • 659
  • 1
  • 7
  • 21
22
votes
3 answers

Is it possible to reuse python @click.option decorators for multiple commands?

I have two Python CLI tools which share a set of common click.options. At the moment, the common options are duplicated: @click.command() @click.option('--foo', is_flag=True) @click.option('--bar', is_flag=True) @click.option('--unique-flag-1',…
Gareth John
  • 223
  • 1
  • 4
21
votes
3 answers

nargs=* equivalent for options in Click

Is there an equivalent to argparse's nargs='*' functionality for optional arguments in Click? I am writing a command line script, and one of the options needs to be able to take an unlimited number of arguments, like: foo --users alice bob charlie…
jpyams
  • 2,949
  • 3
  • 29
  • 56
20
votes
3 answers

Shared options and flags between commands

Say my CLI utility has three commands: cmd1, cmd2, cmd3 And I want cmd3 to have same options and flags as cmd1 and cmd2. Like some sort of inheritance. @click.command() @click.options("--verbose") def cmd1(): …
jirinovo
  • 1,599
  • 2
  • 20
  • 37
19
votes
2 answers

How do I pass variables to other methods using Python's click (Command Line Interface Creation Kit) package

I know it's new, but I like the look of click a lot and would love to use it, but I can't work out how to pass variables from the main method to other methods. Am I using it incorrectly, or is this functionality just not available yet? Seems pretty…
Darren
  • 663
  • 6
  • 14
18
votes
1 answer

Python Click - Supply arguments and options from a configuration file

Given the following program: #!/usr/bin/env python import click @click.command() @click.argument("arg") @click.option("--opt") @click.option("--config_file", type=click.Path()) def main(arg, opt, config_file): print("arg: {}".format(arg)) …
Calvin
  • 532
  • 5
  • 18
18
votes
6 answers

how to debug python click cli application?

I have built a cli application using the click library in python. There is no documentation on how to debug commands. Without click, its easy to just debug python files in IDE, but when we use click, the commands need to be run through…
vishal
  • 3,643
  • 11
  • 51
  • 96
1
2 3
24 25