session: fix subcommand help messages.

main
Jean-François Nguyen 2 years ago
parent 846d4f8a4c
commit 9d81fbb9de

@ -11,4 +11,4 @@ class MicrowattSession(PowerFVSession, core_cls=MicrowattCore):


if __name__ == "__main__": if __name__ == "__main__":
PROG = "python -m {}".format(PurePath(__file__).parent.name) PROG = "python -m {}".format(PurePath(__file__).parent.name)
MicrowattSession(prog=PROG).main() MicrowattSession().main(prog=PROG)

@ -17,17 +17,11 @@ __all__ = ["PowerFVSession"]
class PowerFVCommandExit(Exception): class PowerFVCommandExit(Exception):
pass pass


class PowerFVCommandError(Exception):
pass



class _ArgumentParser(argparse.ArgumentParser): class _ArgumentParser(argparse.ArgumentParser):
def exit(self, status=0, message=None): def exit(self, status=0, message=None):
raise PowerFVCommandExit() raise PowerFVCommandExit()


def error(self, message):
raise PowerFVCommandError()



class PowerFVSession: class PowerFVSession:
def __init_subclass__(cls, *, core_cls, **kwargs): def __init_subclass__(cls, *, core_cls, **kwargs):
@ -38,7 +32,7 @@ class PowerFVSession:
cls.core_cls = core_cls cls.core_cls = core_cls


def __init__(self, prog=None): def __init__(self, prog=None):
self.parser = _ArgumentParser(prog=prog, add_help=False) self.parser = _ArgumentParser(prog="", add_help=False)
self.subparsers = self.parser.add_subparsers(help="commands") self.subparsers = self.parser.add_subparsers(help="commands")
self._checks = dict() self._checks = dict()


@ -47,8 +41,8 @@ class PowerFVSession:
self.add_dump_subparser() self.add_dump_subparser()
self.add_build_subparser() self.add_build_subparser()


def main(self): def main(self, prog):
parser = argparse.ArgumentParser(prog=self.parser.prog) parser = argparse.ArgumentParser(prog=prog)
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument( group.add_argument(
"-i", dest="interact", action="store_true", "-i", dest="interact", action="store_true",
@ -86,8 +80,6 @@ class PowerFVSession:
cmd(**vars(args)) cmd(**vars(args))
except PowerFVCommandExit: except PowerFVCommandExit:
pass pass
except PowerFVCommandError:
self.help()


# Subparsers # Subparsers



Loading…
Cancel
Save