~brenns10/subc

38569814a4d479a0f0bcf8e30cee78965ed89d7b — Stephen Brennan 11 months ago 920347f
rootname optional

Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
2 files changed, 9 insertions(+), 9 deletions(-)

M CHANGELOG.md
M subc/__init__.py
M CHANGELOG.md => CHANGELOG.md +4 -4
@@ 6,10 6,10 @@ Unreleased

Changes to client API:

- Root subclasses must now set "rootname" on their base class. It should
  be set toto the name of the root program (i.e. whatever sys.argv[0]
  would be). This is technically only needed if you use the new
  "simple_sub_parser()" method though.
- Root subclasses can now set "rootname" on their base class. It should
  be set to the name of the root program (i.e. whatever sys.argv[0] would be).
  This is technically only needed if you use the new "simple_sub_parser()"
  method though.
- The optional "help" attribute can be used as a short description, if
  you'd like to make description multiline.
- The optional "group" attribute can be set on each class in order to

M subc/__init__.py => subc/__init__.py +5 -5
@@ 137,10 137,6 @@ class Command(ABC):
    - alias: used as an optional alias for this command (in case you rename it)
    """

    @abstractproperty
    def rootname(self) -> str:
        """The root command name (only needs to be defined on the parent)"""

    @property
    def help_formatter_class(self) -> t.Type[F]:
        return argparse.HelpFormatter


@@ 196,8 192,12 @@ class Command(ABC):
        create a parser for use by documentation generators like
        sphinx-argparse.
        """
        if hasattr(self, "rootname"):
            prog = f"{self.rootname}"
        else:
            prog = self.name
        parser = argparse.ArgumentParser(
            prog=f"{self.rootname} {self.name}",
            prog=prog,
            description=self.description,
            formatter_class=self.help_formatter_class,
        )