Skip to content

cli

trestle.cli ¤

Starting point for the Trestle CLI.

logger ¤

Classes¤

Trestle (CommandBase) ¤

Manage OSCAL files in a human friendly manner.

Source code in trestle/cli.py
class Trestle(CommandBase):
    """Manage OSCAL files in a human friendly manner."""

    subcommands = [
        AssembleCmd,
        AuthorCmd,
        CreateCmd,
        DescribeCmd,
        HrefCmd,
        ImportCmd,
        InitCmd,
        MergeCmd,
        PartialObjectValidate,
        RemoveCmd,
        ReplicateCmd,
        SplitCmd,
        TaskCmd,
        ValidateCmd,
        VersionCmd
    ]

    discovered_plugins = {
        name: importlib.import_module(name)
        for finder,
        name,
        ispkg in pkgutil.iter_modules()
        if name.startswith('trestle_')
    }

    logger.debug(discovered_plugins)
    # This block is uncovered as trestle cannot find plugins in it's unit tests - it is the base module.
    for plugin, value in discovered_plugins.items():  # pragma: nocover
        for _, module, _ in pkgutil.iter_modules([pathlib.Path(value.__path__[0], 'commands')]):
            logger.debug(module)
            command_module = importlib.import_module(f'{plugin}.commands.{module}')
            clsmembers = inspect.getmembers(command_module, inspect.isclass)
            logger.debug(clsmembers)
            for _, cmd_cls in clsmembers:
                # add commands (derived from CommandPlusDocs or CommandBase) to subcommands list
                if issubclass(cmd_cls, CommandBase):
                    # don't add CommandPlusDocs or CommandBase
                    if cmd_cls is not CommandPlusDocs and cmd_cls is not CommandBase:
                        subcommands.append(cmd_cls)
                        logger.info(f'{cmd_cls} added to subcommands from plugin {plugin}')

    def _init_arguments(self) -> None:
        self.add_argument('-v', '--verbose', help=const.DISPLAY_VERBOSE_OUTPUT, action='count', default=0)
        self.add_argument(
            '-tr', '--trestle-root', help='Path of trestle root dir', type=pathlib.Path, default=pathlib.Path.cwd()
        )
discovered_plugins ¤
subcommands ¤

Functions¤

run() ¤

Run the trestle cli.

Source code in trestle/cli.py
def run() -> None:
    """Run the trestle cli."""
    log.set_global_logging_levels()
    logger.debug('Main entry point.')

    exit(Trestle().run())

handler: python