2020-08-04 15:41:19 -04:00
|
|
|
#!/usr/bin/env python3
|
2020-06-17 17:02:57 -04:00
|
|
|
|
2020-06-23 09:54:41 -04:00
|
|
|
"""Simple front-end to the task-specific anod scripts contained in lib."""
|
2020-06-17 17:02:57 -04:00
|
|
|
|
|
|
|
|
from e3.main import Main
|
|
|
|
|
|
2020-06-24 09:09:07 -04:00
|
|
|
from argparse import SUPPRESS, ArgumentParser, _HelpAction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomHelpAction(_HelpAction):
|
|
|
|
|
"""
|
|
|
|
|
Custom help action for ArgumentParser.
|
|
|
|
|
|
|
|
|
|
This action will defer printing help if it sees that the command positional
|
|
|
|
|
argument has already been given and it is on the first pass. This allows
|
|
|
|
|
more specific help to be retrieved by placing the the help option after the
|
|
|
|
|
command argument.
|
|
|
|
|
|
|
|
|
|
Once the first round of argument parsing is completely, call increment_pass
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, option_strings, dest=SUPPRESS, default=SUPPRESS, help=None):
|
|
|
|
|
super(CustomHelpAction, self).__init__(
|
|
|
|
|
option_strings=option_strings, dest=dest, default=default, help=help,
|
|
|
|
|
)
|
|
|
|
|
self.current_pass = 1
|
|
|
|
|
|
|
|
|
|
def __call__(
|
|
|
|
|
self, parser, namespace, values, option_string=None,
|
|
|
|
|
):
|
|
|
|
|
if self.current_pass > 1 or getattr(namespace, "command", None) is None:
|
|
|
|
|
parser.print_help()
|
|
|
|
|
parser.exit()
|
|
|
|
|
|
|
|
|
|
def increment_pass(self) -> None:
|
|
|
|
|
"""Increment the current pass number."""
|
|
|
|
|
self.current_pass += 1
|
2020-06-17 17:02:57 -04:00
|
|
|
|
|
|
|
|
|
2020-06-23 09:54:41 -04:00
|
|
|
if __name__ == "__main__":
|
2020-06-24 09:09:07 -04:00
|
|
|
m = Main(argument_parser=ArgumentParser(add_help=False))
|
|
|
|
|
|
2020-06-17 17:02:57 -04:00
|
|
|
command_arg = m.argument_parser.add_argument(
|
2020-06-23 09:54:41 -04:00
|
|
|
"command",
|
2020-06-24 09:09:30 -04:00
|
|
|
choices=["build", "printenv", "devel-setup"],
|
2020-06-23 09:54:41 -04:00
|
|
|
help="the subcommand to be run.",
|
2020-06-17 17:02:57 -04:00
|
|
|
)
|
|
|
|
|
|
2020-06-24 09:09:07 -04:00
|
|
|
help_arg = m.argument_parser.add_argument(
|
|
|
|
|
"-h", "--help", action=CustomHelpAction, help="show this help message and exit",
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-17 17:02:57 -04:00
|
|
|
m.parse_args(known_args_only=True)
|
|
|
|
|
|
|
|
|
|
# Now that we've parsed the command, we don't want it showing up in help
|
|
|
|
|
# for the subcommands
|
|
|
|
|
command_arg.help = SUPPRESS
|
2020-06-24 09:09:07 -04:00
|
|
|
help_arg.increment_pass()
|
2020-06-17 17:02:57 -04:00
|
|
|
|
2020-06-23 09:54:41 -04:00
|
|
|
if m.args.command == "build":
|
2020-06-17 17:02:57 -04:00
|
|
|
from lib.anod_build import do_build
|
|
|
|
|
|
|
|
|
|
exit(do_build(m))
|
|
|
|
|
|
2020-06-24 09:09:30 -04:00
|
|
|
elif m.args.command == "printenv":
|
|
|
|
|
from lib.anod_printenv import do_printenv
|
2020-06-17 17:02:57 -04:00
|
|
|
|
2020-06-24 09:09:30 -04:00
|
|
|
exit(do_printenv(m))
|
2020-06-17 17:02:57 -04:00
|
|
|
|
2020-06-23 09:54:41 -04:00
|
|
|
elif m.args.command == "devel-setup":
|
2020-06-17 17:02:57 -04:00
|
|
|
from lib.anod_devel_setup import do_devel_setup
|
|
|
|
|
|
|
|
|
|
exit(do_devel_setup(m))
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# cannot happen
|
|
|
|
|
exit(4)
|