In the following Python snippet, why do arguments -h
and --commandfile
work but -c
does not?
Here is the code:
#!/bin/python
import sys, getopt
try:
opts, args = getopt.getopt(sys.argv[1:], "hn:p:", ["commandfile=", "pkeyname="])
except getopt.GetoptError:
print('Error')
sys.exit(2)
# parse the args
for opt, arg in opts:
if opt == '-h':
print('endorse.py [-c,--commandfile] <parent commandfile> <parent keyname> [-k --pkeyname]')
sys.exit()
elif opt in ("-c", "--commandfile"):
print (arg)
elif opt in ("-k", "--pkeyname"):
pkeyname = arg
New contributor
Robert Moskowitz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
The long option commandfile=
does not automatically make its first letter a valid short option. You need to include it in the short options argument.
opts, args = getopt.getopt(sys.argv[1:], "hn:p:c:",["commandfile=","pkeyname="])