from the advice by the accepted answer of my previous question, and from this question, I tried to do:
parser = argparse.ArgumentParser(description="output parser")
line_parser = argparse.ArgumentParser(add_help=False)
line_parser.add_argument("-N", help="Showing first N line",
metavar='integer', type=int)
line_parser.add_argument("-n", help="Showing last n line",
metavar='integer', type=int)
parser.add_argument("opt", help="grep string from file",
nargs=2, metavar=("str", "file"))
subp = parser.add_subparsers()
pscf = subp.add_parser("scf", help="show convergence", parents=[line_parser])#,
pkp = subp.add_parser("kpoint", help="show kpoints")
pnb = subp.add_parser("nband", help="show number of bands")
pmd = subp.add_parser("md", help="Create xyz file for each ionic step for"
" visualization")#, action='store_true')
pfrc = subp.add_parser("force", help="See which atom has maximum force")
# parser.add_argument("--xsf", help="Create xsf file for md(default is xyz)"
# " visualization", action='store_true')
args = parser.parse_args()
This is giving error:
python3 vasp.py --help
Traceback (most recent call last):
File "vasp.py", line 27, in <module>
args = parser.parse_args()
File "/usr/lib64/python3.4/argparse.py", line 1728, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib64/python3.4/argparse.py", line 1760, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/lib64/python3.4/argparse.py", line 1966, in _parse_known_args
start_index = consume_optional(start_index)
File "/usr/lib64/python3.4/argparse.py", line 1906, in consume_optional
take_action(action, args, option_string)
File "/usr/lib64/python3.4/argparse.py", line 1834, in take_action
action(self, namespace, argument_values, option_string)
File "/usr/lib64/python3.4/argparse.py", line 1016, in __call__
parser.print_help()
File "/usr/lib64/python3.4/argparse.py", line 2359, in print_help
self._print_message(self.format_help(), file)
File "/usr/lib64/python3.4/argparse.py", line 2336, in format_help
formatter.add_arguments(action_group._group_actions)
File "/usr/lib64/python3.4/argparse.py", line 272, in add_arguments
self.add_argument(action)
File "/usr/lib64/python3.4/argparse.py", line 257, in add_argument
invocations = [get_invocation(action)]
File "/usr/lib64/python3.4/argparse.py", line 535, in _format_action_invocation
metavar, = self._metavar_formatter(action, default)(1)
ValueError: too many values to unpack (expected 1)
If I remove all of line_parser
, then it works fine. But I need them, as -N and -n will be used in multiple options, though not shown here.
I have read this but haven't managed to assimilate.