557 questions
0
votes
0
answers
48
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
0
answers
90
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 ...
0
votes
0
answers
79
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="...
1
vote
1
answer
68
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
...
1
vote
1
answer
117
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
2
answers
178
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 ...
1
vote
1
answer
146
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
382
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
322
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....
1
vote
0
answers
90
views
Using a '=' as a trigger for click shell completion in my python click application
Intro
It is a strange thing that in pallets click module options can parse a command option in the '--option=value' format, where value is a string, and that is equivalent to '--option value' where ...
1
vote
2
answers
498
views
apscheduler BackgroundScheduler() process is not running in the background
I am working on a project.
Below are the files from which the problem resides.
cli.py
import click
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler(...
-1
votes
1
answer
456
views
Passing Python click options to an ENTRYPOINT using docker run gives error: "executable file not found in $PATH" [closed]
I have a simple python script that I want to run inside of a docker container. It prints a one-line message "Hello {name}". The python script uses the click CLI interface to define the ...
1
vote
0
answers
105
views
How can I use python-click to make a multi-command CLI interface
I'd like to create a CLI for my application that's flexible and extensible. Click seems like the right solution but I'm new to it and have not seen an example that fits what I'm looking for. The ...
0
votes
0
answers
269
views
How to patch a click cli app for unit testing
I have a cli tool written in Python using Click:
cli/main.py
import click
from datetime import *
from .utils import fn
@click.group(invoke_without_command=True, context_settings = { '...
3
votes
1
answer
299
views
Creating a wrapper decorator for click.options()
I am trying to create a wrapper decorator for the click decorator @click.options('--foo', required=True):
import click
def foo_option(func):
orig_decorator = click.option('--foo', required=True)(...
0
votes
0
answers
200
views
How can I get a callback to be run even on the event of an error in the python click framework?
I have a piece of code which I wish to always run at the end of a command execution, regardless of whether the command succeeded or raised an exception. I thought callbacks may be used for this, but ...
0
votes
0
answers
65
views
Args to be optional when an option is used, else required
@cli.command()
@click.option("--list", 'list_steps', default=False, is_flag=True)
@click.argument("elem")
@click.pass_obj
def step(cmd, elem, list_steps):
print(elem)
print(...
1
vote
1
answer
444
views
How to pass a JSON file as an argument to Python click
I'm using click to build a CLI tool. I need my code to open a file in a specified directory (this is what is passed as a command line argument) and parse the json inside that file. What is the best ...
1
vote
0
answers
33
views
Unit Test for Python Click Command Fails on macOS Due to Sandbox Path Difference
I have a Python module that uses the Click library for command-line interfaces.
Assume the module defines a foo function that takes a file path as an argument and calls the bar function with the ...
3
votes
1
answer
2k
views
click.Path sometimes parsed as bytes instead of pathlib.Path
I sometimes have the issue that the click package fails to return a Path when using the click.Path argument, and instead I get a bytes object. Here is a typical code sample which will sometimes cause ...
0
votes
1
answer
104
views
CLI command with Click package Python [closed]
I am using click library in order to call function from one folder and read file and after that to write file.
import sys
import numpy as np
import pandas as pd
import click
def count_unique_port(df:...
0
votes
1
answer
198
views
How to run a command line app continuously until instructed to quit
I'm using Python and Click to create a simple command line app that takes in a number and adds it to a default number. This is what I have so far:
import click
from tqdm import tqdm
init = 5
for i in ...
1
vote
1
answer
211
views
Launch Click CLI Application from inside python code
I would like to integrate a python CLI written using click into a python CLI application built using another framework. Rewriting the calling application is not an option.
As part of the integration, ...
1
vote
1
answer
722
views
python click custom shell completion for command
I have a click application which is running just fine currently.
We want to introduce a new command called api which will dynamically reach into our python sdk and extract sdk methods that can be ...
1
vote
0
answers
846
views
Invoke an HFArgumentParser based script from within a Click command
I have a script trainmodel.py coming from an existing codebase (based on Hugginface ArgumentParsers) with almost 100 different arguments that is based on argparse. The script comes as a main() ...