I was trying CLI using typer, suppose I have two commands say -d and -s,
eg. python main.py -d apples -s red
- -d could be apple, oranges or banana
- -s could be green or red
- if -d is apple then -s must be present, but if -d is oranges or banana then -s is not required.
def app(
device: str = typer.Option(
None,
"--device",
"-d",
help="Select the device you want to proceed with apples, oranges, banana",
callback=__device_callback
is_eager=True,
),
soc: Optional[str] = typer.Option(
"EFR",
"--soc",
"-s",
help="Select the soc for the device type apples. [red or green]",
is_eager=True,
)
):
pass
if __name__ == "__main__":
typer.run(app)
so if I use python main.py -d oranges -> it should run the callback as expected
if I use python main.py -d apples -> it should throw an error saying -s is required
if I use python main.py -d apples -s red -> it should run the callback as expected
- I want to know if this is possible with typer or not?
- If it is possible I need suggestions so I can develop the program