Beispiel #1
0
def list(ctx):
    """Lists all the commands in the current tomb.
    """
    table = tomb_handler.tomb_to_table(ctx)
    if table is None:
        formatter.print_warning(constants.WARN_EMPTY_TOMB)
    else:
        click.echo(table)
Beispiel #2
0
def list(ctx):
    """Lists all the tombs in the catacomb.
    """
    table = catacomb_handler.catacomb_to_table(ctx)
    if table is None:
        formatter.print_warning(constants.WARN_EMPTY_CATACOMB)
    else:
        click.echo(table)
Beispiel #3
0
def rm(ctx, alias):
    """Removes a command from the tomb.

    Arguments:
        alias (str): The alias of the command to remove.
    """
    if tomb_handler.remove_command(ctx, alias):
        formatter.print_success(constants.CMD_RM_OK.format(alias))
    else:
        formatter.print_warning(constants.WARN_CMD_NOT_FOUND.format(alias))
Beispiel #4
0
def create(ctx, tomb_name, force):
    """Creates a new tomb.

    Arguments:
        tomb_name (str): The name/alias of the tomb.
        force (bool): Option to disable prompting the user for confirmation.
    """
    # Check if there currently exists a tomb that has the same name as the
    # one specified before creating a new one.
    if not catacomb_handler.is_existing_tomb(ctx, tomb_name) or force:
        description = click.prompt(constants.CMD_CREATE_DESC_PROMPT)
        catacomb_handler.create_tomb(ctx, tomb_name, description)
        formatter.print_success(constants.CMD_CREATE_OK.format(tomb_name))
    else:
        formatter.print_warning(constants.WARN_TOMB_EXISTS.format(tomb_name))
Beispiel #5
0
def clean(ctx, force):
    """Prompts the user to confirm cleaning of the current tomb. If the user
    confirms the action, the tomb will be reset to it's original empty state.

    Arguments:
        force (bool): Option to disable prompting the user for confirmation.
    """
    if not force:
        # Prompt the user for command details.
        confirm = click.prompt(constants.CMD_CLEAN_PROMPT)

    if force or confirm.lower() == "y":
        tomb_handler.clean_tomb(ctx)
        formatter.print_success(constants.CMD_CLEAN_OK)
    else:
        formatter.print_warning(constants.WARN_ACTION_ABORTED)
Beispiel #6
0
def use(ctx, alias, params):
    """Retrieves a command from the tomb and executes it.

    Arguments:
        alias (str): The alias of the command to execute.
        params (tuple): Optional parameters to be formatted into the command.
    """
    cmd = tomb_handler.get_command(ctx, alias)

    if cmd:
        if params:
            # Substitute any placeholders in the command with the provided
            # parameters.
            cmd = format_cmd(alias, cmd, params)
        # Execute the command.
        os.system(cmd)
    else:
        # The command alias doesn't exist.
        formatter.print_warning(constants.WARN_CMD_NOT_FOUND.format(alias))
Beispiel #7
0
def open(ctx, tomb_name, new):
    """Opens the tomb specified by the user, granting access to all the
    commands stored within it.

    Arguments:
        tomb_name (str): The name/alias of the tomb.
        new (bool): If True, create a new tomb (if it doesn't exist) and then
            switch to it.
    """
    if catacomb_handler.get_current_tomb_name(ctx).lower() == tomb_name:
        # Don't do anything if the specified tomb is already open.
        if new:
            formatter.print_warning(
                constants.WARN_TOMB_EXISTS.format(tomb_name))
        else:
            formatter.print_warning(
                constants.CMD_OPEN_SELF_WARN.format(tomb_name))
    elif new:
        # Create a new tomb and switch to it.
        if not catacomb_handler.is_existing_tomb(ctx, tomb_name):
            description = click.prompt(constants.CMD_OPEN_NEW_DESC_PROMPT)
            catacomb_handler.create_tomb(ctx, tomb_name, description)
            catacomb_handler.open_tomb(ctx, tomb_name)
            formatter.print_success(
                constants.CMD_OPEN_NEW_OK.format(tomb_name))
        else:
            # Do nothing if a tomb with the provided alias already exists.
            formatter.print_warning(
                constants.WARN_TOMB_EXISTS.format(tomb_name))
    elif catacomb_handler.is_existing_tomb(ctx, tomb_name):
        # Otherwise open a new tomb if it exists.
        catacomb_handler.open_tomb(ctx, tomb_name)
        formatter.print_success(constants.CMD_OPEN_OK.format(tomb_name))
    else:
        formatter.print_warning(
            constants.WARN_TOMB_NOT_FOUND.format(tomb_name))
Beispiel #8
0
def bury(ctx, tomb_name, force):
    """Removes the specified tomb from the catacomb.

    Arguments:
        tomb_name (str): The name/alias of the tomb.
        force (bool): Option to disable prompting the user for confirmation.
    """
    if catacomb_handler.get_current_tomb_name(ctx).lower() == tomb_name:
        # Can't bury a tomb if it's currently being used.
        formatter.print_warning(constants.CMD_BURY_SELF_WARN.format(tomb_name))
    elif not catacomb_handler.is_existing_tomb(ctx, tomb_name):
        # If the tomb, specified by the user, can not be found, do nothing.
        formatter.print_warning(
            constants.WARN_TOMB_NOT_FOUND.format(tomb_name))
    else:
        if not force:
            # Prompt the user for confirmation on burying the tomb.
            confirm = click.prompt(constants.CMD_BURY_PROMPT.format(tomb_name))

        if force or confirm.lower() == "y":
            catacomb_handler.remove_tomb(ctx, tomb_name)
            formatter.print_success(constants.CMD_BURY_OK.format(tomb_name))
        else:
            formatter.print_warning(constants.WARN_ACTION_ABORTED)