PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
main.py
Go to the documentation of this file.
1"""Command-line entrypoint for the PICurv conductor."""
2
3import argparse
4
5from .cli import build_main_parser, dispatch_command
6
7
8def _selected_subparser(parser, args):
9 """!
10 @brief The deepest sub-command parser the parsed arguments selected.
11 @param[in] parser Top-level parser.
12 @param[in] args Namespace from parsing with @p parser.
13 @return The parser whose usage describes the selected command.
14 """
15 while True:
16 actions = [action for action in parser._actions if isinstance(action, argparse._SubParsersAction)]
17 name = getattr(args, actions[0].dest, None) if actions else None
18 if name not in (actions[0].choices if actions else {}):
19 return parser
20 parser = actions[0].choices[name]
21
22
23def main():
24 """!
25 @brief Parse command-line arguments and dispatch the requested command.
26 @details Commands that forward arguments to make take its options after `--`; an option
27 given before it is reported by the command it was given to, with that form.
28 """
29 parser = build_main_parser()
30 args, unknown = parser.parse_known_args()
31 if unknown:
32 message = f"unrecognized arguments: {' '.join(unknown)}"
33 if hasattr(args, "make_args"):
34 message += f"; pass make options after '--', as in 'picurv {args.command} -- {unknown[0]}'"
35 _selected_subparser(parser, args).error(message)
36 if getattr(args, "make_args", None) and args.make_args[0] == "--":
37 args.make_args = args.make_args[1:]
38 dispatch_command(args)
_selected_subparser(parser, args)
The deepest sub-command parser the parsed arguments selected.
Definition main.py:8
main()
Parse command-line arguments and dispatch the requested command.
Definition main.py:23