def genfolder(ctx: Context,
              folder: str,
              template: str,
              extension: str = None,
              output: str = None,
              search: str = None,
              exclprefix: list = None,
              root: str = None,
              recurse: bool = False,
              exit: bool = False,
              overwrite: bool = False):
    """
    Command used for, generating the documentation for an entire folder of YAML files.
    """

    # Set the default values.
    if not output:
        output = folder

    if not root:
        root = folder

    # Validate the paths.
    os.path.isdir(folder)
    os.path.isdir(output)
    os.path.isdir(root)
    os.path.isfile(template)

    print(search)

    # Do we want to recursively search?
    files = FileHelper.get_files(folder, search, recurse)
    print(f'Found {len(files)} YAML files to generate the docs for...\n')

    # If there are no files to process throw an error.
    if len(files) == 0:
        raise Exception(
            'No files were found to generate docs for. Double check your search pattern.'
        )

    # Loop through each of the files and generate the docs.
    for idx, file in enumerate(files):

        print(f'[{idx + 1}/{len(files)}] - {file}\n')

        ctx.invoke(genfile,
                   file=file,
                   template=template,
                   output=FileHelper.exchange_file_extension(file, extension),
                   exclprefix=exclprefix,
                   root=folder,
                   exit=exit,
                   overwrite=overwrite)
Beispiel #2
0
def restart(ctx: Context, container: str, pull: bool, recreate: bool,
            proxy: bool):
    """See command Help."""
    print(click.style('[RESTARTING]', fg='green') + ' your stakkr services')
    try:
        ctx.invoke(stop, container=container, proxy=proxy)
    except Exception:
        pass

    ctx.invoke(start,
               container=container,
               pull=pull,
               recreate=recreate,
               proxy=proxy)
Beispiel #3
0
def run_commands(ctx: Context, extra_args: tuple, tty: bool):
    """Run commands for a specific alias"""
    commands = ctx.obj['STAKKR'].get_config()['aliases'][
        ctx.command.name]['exec']
    for command in commands:
        user = command['user'] if 'user' in command else 'root'
        container = command['container']
        args = command['args'] + list(
            extra_args) if extra_args is not None else []

        ctx.invoke(exec_cmd,
                   user=user,
                   container=container,
                   command=args,
                   tty=tty)
Beispiel #4
0
    def global_callback(ctx: Context, global_args: PropertyDict,
                        tasks: List) -> None:
        def move_to_front(task_name: str) -> None:
            for index, task in enumerate(tasks):
                if task.name == task_name:
                    tasks.insert(0, tasks.pop(index))
                    break

        debug_targets = any(
            [task.name in ('openocd', 'gdbgui') for task in tasks])
        if debug_targets:
            # Register the meta cleanup callback -> called on FatalError
            ctx.meta['cleanup'] = debug_cleanup
            move_to_front('gdbgui')  # possibly 2nd
            move_to_front('openocd')  # always 1st
            # followed by "monitor", "gdb" or "gdbtui" in any order

            post_action = ctx.invoke(ctx.command.get_command(
                ctx, 'post_debug'))
            if any(
                [task.name in ('monitor', 'gdb', 'gdbtui') for task in tasks]):
                post_action.action_args['block'] = 0
            else:
                post_action.action_args['block'] = 1
            tasks.append(post_action)  # always last
        if any([task.name == 'openocd' for task in tasks]):
            for task in tasks:
                if task.name in ('gdb', 'gdbgui', 'gdbtui'):
                    task.action_args['require_openocd'] = True
Beispiel #5
0
        def restart(
            ctx: Context, force: bool, apply: bool, service_names: tuple[str, ...]
        ):
            """Restarts service(s)

            Args:
                ctx (Context): Click Context for current CLI.
                force (bool, optional): If True, pass force to all subcommands. Defaults to False.
                apply (bool, optional): If True, configure apply after service(s) are stopped. Defaults to False.
                service_names (tuple[str, ...], optional): The name of the service(s) to restart. If not provided, will restart all
                    services.
            """
            cli_context: CliContext = ctx.obj
            configure_cli = cli_context.commands["configure"]
            # At completion, the invoked commands try to exit the script, so we have to catch
            # the SystemExit exception.
            try:
                ctx.invoke(stop, service_names=service_names)
            except SystemExit:
                pass

            if apply:
                try:
                    ctx.invoke(
                        configure_cli.commands["apply"],
                        message="[autocommit] due to `configure apply` triggered by `service restart --apply`",
                        force=force,
                    )
                except SystemExit:
                    pass

            ctx.invoke(start, force=force, service_names=service_names)