Questions tagged [python-click]

Click is a Python library for creating command line interfaces.

Click is a Python package for creating 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

482 questions
27
votes
1 answer

Add unspecified options to cli command using python-click

I would like to add unspecified options to the cli command using python-click library. So my cli function could look like the following $ my-cmd --option1 value1 --options2 value2 --unknown_var value3 My current code: import…
aitorhh
  • 2,331
  • 1
  • 23
  • 35
26
votes
6 answers

Where should I implement flask custom commands (cli)

Creating custom commands in flask needs access to the app, which is generally created in app.py like this: import click from flask import Flask app = Flask(__name__) @app.cli.command("create-user") @click.argument("name") def create_user(name): …
m0etaz
  • 953
  • 1
  • 8
  • 21
26
votes
2 answers

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
  • 622
  • 2
  • 8
  • 19
26
votes
1 answer

Python Click command names

I'm using the click package for creating a command line tool. However, I would like to have a 'list' command. For example: @click.command @click.option(help='list...') def list(): # do stuff here Is there another way in click to pass in a…
user5004049
  • 691
  • 1
  • 8
  • 17
23
votes
3 answers

How to implement --version using python click?

I want to implement mycommand --version using python click. I have something like this working but it feels kinda clunky. @click.group(invoke_without_command=True, no_args_is_help=True) @click.pass_context @click.option('--version', 'version') def…
wonton
  • 7,568
  • 9
  • 56
  • 93
21
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
  • 743
  • 1
  • 6
  • 14
19
votes
4 answers

Use Flask's Click CLI with the app factory pattern

I define my Flask application using the app factory pattern. When using Flask-Script, I can pass the factory function to the Manager. I'd like to use Flask's built-in Click CLI instead. How do I use the factory with Click? My current code uses…
user3313834
  • 7,327
  • 12
  • 56
  • 99
19
votes
4 answers

Click: "Got unexpected extra arguments" when passing string

import click @cli.command() @click.argument("namespace", nargs=1) def process(namespace): ..... @cli.command() def run(): for namespace in KEYS.iterkeys(): process(namespace) Running run('some string') produces: Error: Got unexpected…
Benjamin Dean
  • 709
  • 1
  • 6
  • 15
18
votes
1 answer

Python click, Can you make -h as an alias

I have recently found the click library (http://click.pocoo.org/6/) and I love it. I am trying to figure out if it is possible to create an alias for the --help option which shortcuts to the help. So, for example: app.py --help gives the help for…
Jeff
  • 4,285
  • 15
  • 63
  • 115
17
votes
1 answer

Possible to do multiple nested commands in Click 6

I am going to write something very basic so as to explain what I'm looking to make happen. I have written some code to do some interesting WordPress administration. The program will create instances but also create https settings for apache. What…
17
votes
5 answers

Pyinstaller on a setuptools package

I'm attempting to run PyInstaller on a CLI app I am building in Python using the Click library. I'm having trouble building the project using PyInstaller. PyInstaller has a document in their GitHub wiki titled Recipe Setuptools Entry Point, which…
Scott Crooks
  • 1,523
  • 4
  • 24
  • 39
17
votes
2 answers

Python Click: Having the group execute code AFTER a command

I have a click.group() defined, with about 10 commands in it. I understand how to use a group to run code before the code in the command, but I also want to run some code AFTER each command is run. Is that possible with click?
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
17
votes
2 answers

Python click: Make some options hidden

I'm using click to build a CLI in Python. I have several options to the command I'm defining, and I want some of them to be hidden in --help. How can I do that?
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
16
votes
2 answers

How to add common options to sub commands which can go *after* the name of the sub command

Using the CLI library click I have an application script app.py with the two sub commands read and write: @click.group() @click.pass_context def cli(ctx): pass @cli.command() @click.pass_context def read(ctx): …
halloleo
  • 9,216
  • 13
  • 64
  • 122
16
votes
4 answers

Does click lib provide a way to print the builtin help message?

I am using the click lib. In my code , sometimes I want to print help msg , But the only way I know is : python xxx --help But I want to print the help msg in my code using a certain function , for example: click.print_help_msg() Is there a…
ruiruige1991
  • 615
  • 1
  • 10
  • 21
1
2
3
32 33