I want to write a CLI hello that takes a FILENAME as an argument except when the option -s STRING is given, in which case the STRING is processed directly. The program should print hello {NAME} where name is either given via the STRING or taken to be the contents of the file FILENAME.
example:
$ cat myname.txt
john
$ hello myname.txt
hello john
$ hello -s paul
hello paul
A possible workaround is to use two options:
@click.command()
@click.option("-f", "--filename", type=str)
@click.option("-s", "--string", type=str)
def main(filename: str, string: str):
if filename:
...
if string:
....
but that means that I must call hello with a flag.