aboutsummaryrefslogtreecommitdiffstats
path: root/ves-export.sh
blob: 0f360068f427f151b3452ac15eb8eb33870fe1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
#
# Set an environment variable within an sh-ves environment. If the target
# environment is currently active, the variable is also exported into the
# live shell.
#
ves_export() {
    env=""
    case $1 in
        --env=*)
            env="${1#--env=}"
            shift
            ;;
    esac

    if [ "$#" -lt 2 ]; then
        printf "ERROR: Insufficient arguments. usage: ves export [--env=<name>] <variable> <value>\n" >&2
        return 2
    fi

    var="$1"
    value="$2"

    if ! env=$(_shves_resolve_env "$env"); then
        return 1
    fi

    if ! _shves_check_var_name "$var"; then
        return 1
    fi

    _shves_set_var "$SHVES_ENV_DIR/$env" "$var" "$value"

    if [ "$env" = "$SHVES_ENV_NM" ]; then
        _shves_live_export "$var" "$value"
    fi

    return 0
}