typer
typer copied to clipboard
Is there a way to override the options of a command?
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Typer documentation, with the integrated search.
- [X] I already searched in Google "How to X in Typer" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to Typer but to Click.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
import typer
app = typer.Typer()
@app.command()
def hi(name: str):
print("hi ", name)
# I want to do something like this
app.get_command("hi").options["name"] = typer.Option(..., hidden=True)
# Basically, I want to dynamically manipulate the options of a specific command. Is something like this achievable?
Description
I have a use case, where I want to override the typer command options. Basically, after decorating a function as typer.command()
I want to manipulate the options of this certain command later. Is this possible? I included a minimal example of what I want to do.
Operating System
Linux
Operating System Details
ubuntu 20.04
Typer Version
0.4.1
Python Version
3.8
Additional Context
No response
From the sidelines: It's generally best practice to pose some minimal version of your specific usecase in issues so as not to fall into the trap of the xy problem.
Though perhaps you could use a callback to solve this issue? You could, based on the context, modify app commands and call them with variable numbers of parameters?