I'm trying to use argparse but I keep having the issue where for some reason my positional parameters are required to be first on the command line. I want the positional to be last since it is a list of file names.
self.parser = ArgumentParser(description=program_license,
formatter_class=RawDescriptionHelpFormatter,
conflict_handler='resolve')
self.parser.add_argument('-V', '--version',
action='version',
version=program_version_message)
self.parser.add_argument('--logfile', action='store',
dest='logfile', default='daddyvision.log')
self.parser.add_argument('prog', help=SUPPRESS, nargs=1)
self.parser.add_argument('library', metavar="library", nargs='*')
group_loglvl = self.parser.add_mutually_exclusive_group()
group_loglvl.add_argument("--verbose", dest="loglevel",
action="store_const", const="VERBOSE",
default='INFO')
group_loglvl.add_argument("--debug", dest="loglevel",
action="store_const", const="DEBUG")
group_loglvl.add_argument("--trace", dest="loglevel",
action="store_const", const="TRACE")
group_loglvl.add_argument("--quiet", dest="loglevel",
action="store_const", const="WARNING")
group_loglvl.add_argument("--errors", dest="loglevel",
action="store_const", const="ERROR")
args = self.parser.parse_args(arg)
if my command line is: pgm --error filename I get "error: unrecognized arguments: filename"
if my cmd line is pgm filename --error it works without error.
What am I doing wrong. Everything I've read leads me to believe that the positional can come first or last. Python 2.7 environment.
If I make the positional requires (nargs='+') it works but the parm is optional.