Skip to content

command_docs

trestle.core.commands.command_docs ¤

Trestle command abstraction.

Improves parsing until such a point as ILCLI is fixed.

Attributes¤

logger = logging.getLogger(__name__) module-attribute ¤

Classes¤

CommandBase ¤

Bases: 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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__
Functions¤
__init__(parser=None, parent=None, name=None, out=None, err=None) ¤

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

Source code in trestle/core/commands/command_docs.py
40
41
42
43
44
45
46
47
48
49
50
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 ¤

Bases: 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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