Is it possible to specify two input types for a click.option
, one of which the supplied value has to be in?
In a normal python function with typing, I'd declare it like so:
from typing import Union
def fun(x: Union[int, str]):
if isinstance(x, str):
x = int(x)
return x**2
so x
should be either an int
or str
.
In click
I want to achieve the same thing, just with the addition that the script fails when the input type isn't in the defined ones.
I've tried
@click.option('-x', type=(click.INT, click.STRING))
but that seems to be only for occasions with multiple arguments.
string
toint
then maybe simply useint(variable)
without checking type. If you useint(integer_number)
then you get the same integer number. If you useint(string_number)
then you get value converted to integer number. – Allanfile
andcontext
- forPython
both would be only strings. I would rather use two different variables for this - ie.-f
forfile
and-t
fortext/content
- first function (assigned to-f
) would load file and run second function (assigned to-t
). – Allan