I have a python and argparse script, one of the optional arguments adds transliteration:
parser = argparse.ArgumentParser()
parser.add_argument('-t', '
action='store_true',
help='display a text')
parser.add_argument('-s', '--search',
dest='string',
action='store',
type=str,
help='search in a text')
parser.add_argument('--translit',
action='store_true',
help='transliterate output; usage: prog [-t | -d STRING] --translit')
results = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
elif results.text and results.translit::
translit(display_text())
elif results.text and results.translit::
display_text()
elif results.string and results.translit:
translit(search(results.string))
elif results.string:
search(results.string)
Output:
usage: prog [-h] [-t] [-s STRING] [--translit]
optional arguments:
-h,
-t,
-s STRING,
[-t | -s STRING]
There is no result when I run prog -translit. I need a line that looks like this:
usage: prog [-h] [-t] [-s STRING] [[-t | -s STRING] --translit]
When I run prog -translit, the output line should be:
prog: error: argument --translit: usage: [[-t | -s STRING] --translit]
How can i do this?
source
share