Skip to content

command_docs

trestle.core.commands.command_docs ¤

Trestle command abstraction.

Improves parsing until such a point as ILCLI is fixed.

logger ¤

Classes¤

CommandBase (Command) ¤

Linear extension to the ILCLI interface to use documentation string more.

Trestle commands not requiring trestle-root should extend from this class.

Source code in trestle/core/commands/command_docs.py
class CommandBase(Command):
    """Linear extension to the ILCLI interface to use documentation string more.

    Trestle commands not requiring trestle-root should extend from this class.
    """

    # Example commands extedning from this class - init', 'trestle', 'version', 'partial-object-validate'
    def __init__(
        self,
        parser: Optional[argparse.ArgumentParser] = None,
        parent: Optional[Command] = None,
        name: Optional[str] = None,
        out: Optional[TextIO] = None,
        err: Optional[TextIO] = None
    ) -> None:
        """Override default ILCLI behaviour to include class documentation in command help description."""
        super(CommandBase, self).__init__(parser, parent, name, out, err)
        self.parser.description = self.__doc__
Methods¤
__init__(self, parser=None, parent=None, name=None, out=None, err=None) special ¤

Override default ILCLI behaviour to include class documentation in command help description.

Source code in trestle/core/commands/command_docs.py
def __init__(
    self,
    parser: Optional[argparse.ArgumentParser] = None,
    parent: Optional[Command] = None,
    name: Optional[str] = None,
    out: Optional[TextIO] = None,
    err: Optional[TextIO] = None
) -> None:
    """Override default ILCLI behaviour to include class documentation in command help description."""
    super(CommandBase, self).__init__(parser, parent, name, out, err)
    self.parser.description = self.__doc__

CommandPlusDocs (CommandBase) ¤

This class validates trestle-root argument.

Trestle commands requiring trestle-root should extend from this class. All commands that extend this class will validate the state of trestle workspace.

Source code in trestle/core/commands/command_docs.py
class CommandPlusDocs(CommandBase):
    """This class validates trestle-root argument.

    Trestle commands requiring trestle-root should extend from this class.
    All commands that extend this class will validate the state of trestle workspace.
    """

    def _validate_arguments(self, args: argparse.ArgumentParser) -> int:
        """Check trestle-root argument is a valid trestle root directory."""
        root = file_utils.extract_trestle_project_root(args.trestle_root)  # type: ignore
        if root is None:
            logger.error(f'Given directory {args.trestle_root} is not in a valid trestle root directory')
            return CmdReturnCodes.TRESTLE_ROOT_ERROR.value
        is_oscal_dir_valid = file_utils.check_oscal_directories(args.trestle_root)  # type: ignore
        if not is_oscal_dir_valid:
            return CmdReturnCodes.TRESTLE_ROOT_ERROR.value
        args.trestle_root = root  # type: ignore
        return CmdReturnCodes.SUCCESS.value

handler: python