"deployment/vscode:/vscode.git/clone" did not exist on "bbf4760ca3ae7bab222f453f446e2b152a47fbbe"
bash-completion 3.07 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
# list of commands/arguments
2
3
4
5
__nnictl_cmds="create resume update stop trial experiment config webui log"
__nnictl_create_cmds="--config --port"
__nnictl_resume_cmds="--port"
__nnictl_update_cmds="searchspace concurrency duration trialnum"
liuzhe-lz's avatar
liuzhe-lz committed
6
7
8
__nnictl_update_searchspace_cmds="--filename"
__nnictl_update_concurrency_cmds="--value"
__nnictl_update_duration_cmds="--value"
9
__nnictl_update_trialnum_cmds="--value"
liuzhe-lz's avatar
liuzhe-lz committed
10
11
__nnictl_trial_cmds="ls kill"
__nnictl_trial_kill_cmds="--trialid"
12
13
14
__nnictl_webui_cmds="url"
__nnictl_experiment_cmds="show list status"
__nnictl_experiment_list_cmds="all"
liuzhe-lz's avatar
liuzhe-lz committed
15
__nnictl_config_cmds="show"
16
__nnictl_log_cmds="stdout stderr trial"
liuzhe-lz's avatar
liuzhe-lz committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__nnictl_log_stdout_cmds="--tail --head --path"
__nnictl_log_stderr_cmds="--tail --head --path"

# list of arguments that accept a file name
__nnictl_file_args=" --config -c --filename -f "

# list of arguments that accept an experiment ID
__nnictl_experiment_args=" --experiment -e "

# list of arguments that accept a trial ID
__nnictl_trial_args=" --trialid -t "


# remove already set arguments from candidates
__nnictl_remain_args()
{
    local ret=${!1}  # ret = $__nnictl_xxx_cmds
    # for arg in COMP_WORDS[:-1]:
    for arg in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}"; do
        if [[ $arg == --* ]]; then
            local ret=${ret/$arg/}  # remove it from $ret
        fi
    done
    echo $ret
}

_nnictl()
{
liuzhe-lz's avatar
liuzhe-lz committed
45
    if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then
liuzhe-lz's avatar
liuzhe-lz committed
46
47
48
        # completing frst argument from __nnictl_cmds
        COMPREPLY=($(compgen -W "$__nnictl_cmds" -- "${COMP_WORDS[1]}"))

liuzhe-lz's avatar
liuzhe-lz committed
49
    elif [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
liuzhe-lz's avatar
liuzhe-lz committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        # completing second argument from __nnictl_${FirstArg}_cmds
        local args=__nnictl_${COMP_WORDS[1]}_cmds
        COMPREPLY=($(compgen -W "${!args}" -- "${COMP_WORDS[2]}"))

    elif [[ ${COMP_WORDS[-2]} != -* ]]; then
        # last argument does not starts with "-", so this one is likely to be "--xxx"
        if [[ ${COMP_WORDS[2]} == -* ]]; then
            # second argument starts with "-", use __nnictl_${FirstArg}_cmds
            local args=__nnictl_${COMP_WORDS[1]}_cmds
        else
            # second argument is a word, use __nnictl_${FirstArg}_{SecondArg}_cmds
            local args=__nnictl_${COMP_WORDS[1]}_${COMP_WORDS[2]}_cmds
        fi
        # remove already set arguments from candidates
        local remain_args=$(__nnictl_remain_args ${args})
        COMPREPLY=($(compgen -W "$remain_args" -- "${COMP_WORDS[-1]}"))

    elif [[ $__nnictl_file_args =~ " ${COMP_WORDS[-2]} " ]]; then
        # complete file names
        COMPREPLY=($(compgen -f "${COMP_WORDS[-1]}"))

    elif [[ $__nnictl_experiment_args =~ " ${COMP_WORDS[-2]} " ]]; then
        # complete experiment IDs
        local experiments=$(ls ~/nni/experiments 2>/dev/null)
        COMPREPLY=($(compgen -W "$experiments" -- "${COMP_WORDS[-1]}"))

    elif [[ $__nnictl_trial_args =~ " ${COMP_WORDS[-2]} " ]]; then
        # complete trial IDs
        local trials=$(ls -d ~/nni/experiments/*/trials/* 2>/dev/null | grep -o '[^/]*$')
        COMPREPLY=($(compgen -W "$trials" -- "${COMP_WORDS[-1]}"))
    fi
}

Zejun Lin's avatar
Zejun Lin committed
83
complete -o nospace -F _nnictl nnictl