557 questions
-1
votes
0
answers
50
views
Use fallback subcommand if no subcommand matches [duplicate]
I have a tool that uses Click to define its CLI interface. It uses groups to achieve a subcommand hierarchy. So, if it is mytool, we have commands like mytool edit, mytool show, mytool execute script1....
0
votes
1
answer
31
views
click.option with deprecated=str failed with unexpected keyword argument
Here is short sample, which uses click==8.1.7
# main.py
import click
@click.command
@click.option(
"--disable-all",
is_flag=True,
default=False,
deprecated="Please use --...
0
votes
0
answers
96
views
Python Click Shell Completion
i am currently trying to get a compiled python project which is using click 8.0.4 running with shell_completion.
My project contains multiple downstream scripts, which should support the ...
2
votes
1
answer
151
views
Click help text shows 'dynamic' when an option has the default set to a lambda
I have this code in a CLI:
@click.option(
"--username",
default=lambda: os.environ.get("USER", None),
show_default=True,
help="User name for SSH configuration.&...
0
votes
0
answers
80
views
Define a dynamic default value of an option based on another option when using Typer
I have the following ~minimal code:
from typing import Annotated
import typer
def main(
username: Annotated[
str,
typer.Option("--username", "-u", help="...
0
votes
0
answers
33
views
Python click CLI subcommand multiple times
I am new to the click CLI library, so this might be something trivial.
I have a script which has one group and one subcommand, something like this. It is a ML application which has a training phase ...
1
vote
1
answer
69
views
Click: How to propagate the exit code back to the group
I have a script which use click.group to provide sub commands. Each of the sub command might pass or fail. How do I propagate the exit code from the sub commands back to main?
import click
import sys
...
4
votes
1
answer
48
views
Get Click to not expand variables in argument
I have a simple Click app like this:
import click
@click.command()
@click.argument('message')
def main(message: str):
click.echo(message)
if __name__ == '__main__':
main()
When you pass an ...
1
vote
1
answer
120
views
How to force Python Click to emit colors when writing to a pipe?
When click.secho("helo", fg="yellow") writes to a pipe, the colors are stripped by default. If there a way to force click to emit the color codes even when stdout is a pipe?
...
0
votes
0
answers
68
views
How to create a terminal-like python pipe?
Some programs emit colored text when their output is connected to a terminal, and non colored text when their output goes to a pipe.
Is there a way in Python to open a pipe to a subprocess such that ...
0
votes
2
answers
182
views
How to override the help text of a shared python click option?
I am using python click options that are shared by multiple commands, as described at https://stackoverflow.com/a/77732441.
Is there a simple way to customize the help= text of the list option in the ...
2
votes
1
answer
232
views
How to use windows_expand_args with single command click program
I have a Python program and am using Click to process the command line. I have a single command program, as in the example below. On Windows I would like to pass in a valid glob expression like *.py ...
1
vote
1
answer
154
views
How to use Python Click's `ctx.with_resource` to capture tracebacks in (sub-)commands/groups
In Click, Context.with_resource's documentation states it can be used to:
[r]egister a resource as if it were used in a with statement. The resource will be cleaned up when the context is popped.
...
2
votes
1
answer
121
views
How do I know if flag was passed by the user or has default value?
Sample code:
import click
@click.command
@click.option('-f/-F', 'var', default=True)
def main(var):
click.echo(var)
main()
Inside main() function, how can I check if var parameter got True value ...
2
votes
1
answer
383
views
Changing command order in Python's Typer
I want Typer to display my commands in the order I have initialized them and it displays those commands in alphabetic order.
I have tried different approaches including this one: https://github.com/...