Skip to content

example

Merlin CLI example command module.

This module defines the ExampleCommand class, which integrates into the Merlin command-line interface to support downloading and setting up example workflows.

ExampleCommand

Bases: CommandEntryPoint

Handles example CLI command for downloading built-in Merlin examples.

Methods:

Name Description
add_parser

Adds the example command to the CLI parser.

process_command

Processes the CLI input and dispatches the appropriate action.

Source code in merlin/cli/commands/example.py
class ExampleCommand(CommandEntryPoint):
    """
    Handles `example` CLI command for downloading built-in Merlin examples.

    Methods:
        add_parser: Adds the `example` command to the CLI parser.
        process_command: Processes the CLI input and dispatches the appropriate action.
    """

    def add_parser(self, subparsers: ArgumentParser):
        """
        Add the `example` command parser to the CLI argument parser.

        Parameters:
            subparsers (ArgumentParser): The subparsers object to which the `example` command parser will be added.
        """
        example: ArgumentParser = subparsers.add_parser(
            "example",
            help="Generate an example merlin workflow.",
            formatter_class=RawTextHelpFormatter,
        )
        example.set_defaults(func=self.process_command)
        example.add_argument(
            "workflow",
            action="store",
            type=str,
            help="The name of the example workflow to setup. Use 'merlin example list' to see available options.",
        )
        example.add_argument(
            "-p",
            "--path",
            action="store",
            type=str,
            default=None,
            help="Specify a path to write the workflow to. Defaults to current working directory",
        )

    def process_command(self, args: Namespace):
        """
        CLI command to set up or list Merlin example workflows.

        This function either lists all available example workflows or sets
        up a specified example workflow to be run in the root directory. The
        behavior is determined by the `workflow` argument.

        Args:
            args: Parsed command-line arguments, which may include:\n
                - `workflow`: The action to perform; should be "list"
                to display all examples or the name of a specific example
                workflow to set up.
                - `path`: The directory where the example workflow
                should be set up. Only applicable when `workflow` is not "list".
        """
        if args.workflow == "list":
            print(list_examples())
        else:
            print(banner_small)
            setup_example(args.workflow, args.path)

add_parser(subparsers)

Add the example command parser to the CLI argument parser.

Parameters:

Name Type Description Default
subparsers ArgumentParser

The subparsers object to which the example command parser will be added.

required
Source code in merlin/cli/commands/example.py
def add_parser(self, subparsers: ArgumentParser):
    """
    Add the `example` command parser to the CLI argument parser.

    Parameters:
        subparsers (ArgumentParser): The subparsers object to which the `example` command parser will be added.
    """
    example: ArgumentParser = subparsers.add_parser(
        "example",
        help="Generate an example merlin workflow.",
        formatter_class=RawTextHelpFormatter,
    )
    example.set_defaults(func=self.process_command)
    example.add_argument(
        "workflow",
        action="store",
        type=str,
        help="The name of the example workflow to setup. Use 'merlin example list' to see available options.",
    )
    example.add_argument(
        "-p",
        "--path",
        action="store",
        type=str,
        default=None,
        help="Specify a path to write the workflow to. Defaults to current working directory",
    )

process_command(args)

CLI command to set up or list Merlin example workflows.

This function either lists all available example workflows or sets up a specified example workflow to be run in the root directory. The behavior is determined by the workflow argument.

Parameters:

Name Type Description Default
args Namespace

Parsed command-line arguments, which may include:

  • workflow: The action to perform; should be "list" to display all examples or the name of a specific example workflow to set up.
  • path: The directory where the example workflow should be set up. Only applicable when workflow is not "list".
required
Source code in merlin/cli/commands/example.py
def process_command(self, args: Namespace):
    """
    CLI command to set up or list Merlin example workflows.

    This function either lists all available example workflows or sets
    up a specified example workflow to be run in the root directory. The
    behavior is determined by the `workflow` argument.

    Args:
        args: Parsed command-line arguments, which may include:\n
            - `workflow`: The action to perform; should be "list"
            to display all examples or the name of a specific example
            workflow to set up.
            - `path`: The directory where the example workflow
            should be set up. Only applicable when `workflow` is not "list".
    """
    if args.workflow == "list":
        print(list_examples())
    else:
        print(banner_small)
        setup_example(args.workflow, args.path)