def METHOD_NAME(ctx, option, value, globally, append, remove):
    """Set an AiiDA option.
    List values are split by whitespace, e.g. "a b" becomes ["a", "b"].
    """
    from aiida.manage.configuration import Config, ConfigValidationError, Profile
    if append and remove:
        echo.echo_critical('Cannot flag both append and remove')
    config: Config = ctx.obj.config
    profile: Profile | None = ctx.obj.profile
    if option.global_only:
        globally = True
    # Define the string that determines the scope: for specific profile or globally
    scope = profile.name if (not globally and profile) else None
    scope_text = f"for '{profile.name}' profile" if (not globally and profile) else 'globally'
    if append or remove:
        try:
            current = config.get_option(option.name, scope=scope)
        except ConfigValidationError as error:
            echo.echo_critical(str(error))
        if not isinstance(current, list):
            echo.echo_critical(f'cannot append/remove to value: {current}')
        if append:
            value = current + [value]
        else:
            value = [item for item in current if item != value]
    # Set the specified option
    try:
        value = config.set_option(option.name, value, scope=scope)
    except ConfigValidationError as error:
        echo.echo_critical(str(error))
    config.store()
    echo.echo_success(f"'{option.name}' set to {value} {scope_text}")