import json


def get_node_execution_command(executor, node, map_variable=None, over_write_run_id=None) -> str:
    """
    A utility function to standardize execution call to a node via command line.

    Args:
        executor (object): The executor class.
        node (object): The Node to execute
        map_variable (str, optional): If the node belongs to a map step. Defaults to None.

    Returns:
        str: The execution command to run a node via command line.
    """
    run_id = executor.run_id

    if over_write_run_id:
        run_id = over_write_run_id

    action = (f'magnus execute_single_node {run_id} '
              f'{node.command_friendly_name()} --file {executor.pipeline_file}'
              )

    if executor.variables_file:
        action = action + f' --var-file {executor.variables_file}'

    if map_variable:
        action = action + f" --map-variable '{json.dumps(map_variable)}'"

    if executor.configuration_file:
        action = action + f' --config-file {executor.configuration_file}'

    if executor.parameters_file:
        action = action + f' --parameters-file {executor.parameters_file}'

    if executor.tag:
        action = action + f' --tag {executor.tag}'

    return action