python-click

Optional argument in command with click

怎甘沉沦 提交于 2021-02-18 22:30:12
问题 I am trying to accomplish something not very standard for CLI parsing with Click and it only works partially: main CLI has multiple sub-commands (in sample below 'show' and 'check') both those commands might have optional argument, but the argument is preceding them not following I decided to handle that argument in the group "above" it and pass the value in the context Sample: import click @click.group() @click.argument('hostname', required=False) @click.pass_context def cli(ctx, hostname

Click tools with optional arguments

瘦欲@ 提交于 2021-02-16 20:22:46
问题 I want to write a CLI hello that takes a FILENAME as an argument except when the option -s STRING is given, in which case the STRING is processed directly. The program should print hello {NAME} where name is either given via the STRING or taken to be the contents of the file FILENAME. example : $ cat myname.txt john $ hello myname.txt hello john $ hello -s paul hello paul A possible workaround is to use two options: @click.command() @click.option("-f", "--filename", type=str) @click.option("

Using Click Commands in Python

爱⌒轻易说出口 提交于 2021-02-11 13:42:06
问题 I have a Python program and I want to run it using command: myprogram --readpower=some argument Code import click import csv import json import sys @click.group(invoke_without_command=True) @click.option('--version', is_flag=True, default=False, help='Prints out pyisg package version being used') def cli(version): """ This utility is used to convert a CSV file to JSON file """ if version: print("This is version 1.0 software") sys.exit() @cli.command() @click.option('--readpower', type=str,

Python click application required parameters have precedence over sub command help option

安稳与你 提交于 2021-02-04 21:19:28
问题 I'm building a click 7.x application with Python 3.6 and am having some issues getting help to work for sub commands. I have a global option that is required and this option is being reported as missing when I run help on any sub command. For example, given the following dummy script cli.py : import click @click.group() @click.option('--directory', required=True) def cli(directory): """ this is a tool that has an add and remove command """ click.echo(directory) @cli.command() @click.overwrite

Python click application required parameters have precedence over sub command help option

社会主义新天地 提交于 2021-02-04 21:18:00
问题 I'm building a click 7.x application with Python 3.6 and am having some issues getting help to work for sub commands. I have a global option that is required and this option is being reported as missing when I run help on any sub command. For example, given the following dummy script cli.py : import click @click.group() @click.option('--directory', required=True) def cli(directory): """ this is a tool that has an add and remove command """ click.echo(directory) @cli.command() @click.overwrite

Testing Python Click Command Exceptions

 ̄綄美尐妖づ 提交于 2021-01-07 03:00:14
问题 I am trying to test the raising of exceptions by a command implemented with the Click package. This is my command: @click.option( '--bucket_name', ...) @click.option( '--group_id', ...) @click.option( '--artifact_id', ...) @click.option( '--version', ...) @click.option( '--artifact_dir', required=False, default='downloads/artifacts/', ...) @click.command() def download_artifacts( bucket_name, group_id, artifact_id, version, artifact_dir ): logger.info( f"bucket_name: {bucket_name}, " f"group