555 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
36
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 --...
2
votes
1
answer
153
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
85
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
79
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
49
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
123
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
188
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
242
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
164
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
125
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
406
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/...
0
votes
1
answer
71
views
Keep python click argument case
Using the following click application:
from rich.traceback import install
install(show_locals=True)
import click
@click.command()
@click.argument("PATH", envvar="PATH", nargs=-1, ...
0
votes
1
answer
343
views
Unable to read file with click.Path option inside runner.isolated_filesystem()
I am using click for the very first time to create a cli program using Python 3.12.2.
I created a simple click command that takes an option (the '-f' / '--file' option) as a filepath with type click....