"...targets/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "a82ea1d6416d9d7ac0adeed46789c05edcbe9e52"
bash-completion 5.54 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
# list of commands/arguments
2
3
4
__nnictl_cmds="create resume update stop trial experiment platform import export webui config log package tensorboard top"
__nnictl_create_cmds="--config --port --debug"
__nnictl_resume_cmds="--port --debug"
5
__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"
10
11
12
13
14
15
16
17
18
19
20
__nnictl_stop_cmds="--port all"
__nnictl_trial_cmds="ls kill codegen"
__nnictl_trial_kill_cmds="--trial_id"
__nnictl_trial_codegen_cmds="--trial_id"
__nnictl_experiment_cmds="show status list delete"
__nnictl_experiment_list_cmds="--all"
__nnictl_experiment_delete_cmds="--all"
__nnictl_platform_cmds="clean"
__nnictl_platform_clean_cmds="--config"
__nnictl_import_cmds="--filename"
__nnictl_export_cmds="--type --filename"
21
__nnictl_webui_cmds="url"
liuzhe-lz's avatar
liuzhe-lz committed
22
__nnictl_config_cmds="show"
23
__nnictl_log_cmds="stdout stderr trial"
liuzhe-lz's avatar
liuzhe-lz committed
24
25
__nnictl_log_stdout_cmds="--tail --head --path"
__nnictl_log_stderr_cmds="--tail --head --path"
26
27
28
29
30
31
__nnictl_log_trial_cmds="--trial_id"
__nnictl_package_cmds="install show"
__nnictl_package_install_cmds="--name"
__nnictl_tensorboard_cmds="start stop"
__nnictl_tensorboard_start_cmds="--trial_id --port"
__nnictl_top_cmds="--time"
liuzhe-lz's avatar
liuzhe-lz committed
32

33
34
35
36
# list of commands that accept an experiment ID as second argument
__nnictl_2st_expid_cmds=" resume stop import export "
# list of commands that accept an experiment ID as third argument
__nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard "
liuzhe-lz's avatar
liuzhe-lz committed
37
38
39
40
41
42
43
44


# 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
45
        local ret=${ret/$arg/}  # remove it from $ret
liuzhe-lz's avatar
liuzhe-lz committed
46
47
48
49
    done
    echo $ret
}

50
51
52
53
54
55
56
57
58
59
60
# complete files with specific extension
__nnictl_complete_extension()
{
    COMPREPLY=($(compgen -f -X "!*.$1" -- ${COMP_WORDS[-1]}))
    if [[ -z "${COMPREPLY[*]}" ]]; then
        # if there is no matching file here, search in sub-directories
        COMPREPLY=($(compgen -d -S "/" -- ${COMP_WORDS[-1]}))
        compopt -o nospace
    fi
}

liuzhe-lz's avatar
liuzhe-lz committed
61
62
_nnictl()
{
63
64
65
    local cur=${COMP_WORDS[-1]}
    local last=${COMP_WORDS[-2]}

liuzhe-lz's avatar
liuzhe-lz committed
66
    if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then
liuzhe-lz's avatar
liuzhe-lz committed
67
68
69
        # completing frst argument from __nnictl_cmds
        COMPREPLY=($(compgen -W "$__nnictl_cmds" -- "${COMP_WORDS[1]}"))

liuzhe-lz's avatar
liuzhe-lz committed
70
    elif [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
liuzhe-lz's avatar
liuzhe-lz committed
71
72
73
74
        # completing second argument from __nnictl_${FirstArg}_cmds
        local args=__nnictl_${COMP_WORDS[1]}_cmds
        COMPREPLY=($(compgen -W "${!args}" -- "${COMP_WORDS[2]}"))

75
76
77
78
79
80
81
        # add experiment IDs to candidates if desired
        if [[ " resume stop import export " =~ " ${COMP_WORDS[1]} " ]]; then
            local experiments=$(ls ~/nni/experiments 2>/dev/null)
            COMPREPLY+=($(compgen -W "$experiments" -- $cur))
        fi

    elif [[ $last != -* || $last == --debug ]]; then
liuzhe-lz's avatar
liuzhe-lz committed
82
        # last argument does not starts with "-", so this one is likely to be "--xxx"
83
84
85
        local args=__nnictl_${COMP_WORDS[1]}_${COMP_WORDS[2]}_cmds
        if [[ $args =~ "-" || -z ${!args} ]]; then
            # the second argument starts with "-", use __nnictl_${FirstArg}_cmds
liuzhe-lz's avatar
liuzhe-lz committed
86
87
88
89
            local args=__nnictl_${COMP_WORDS[1]}_cmds
        fi
        # remove already set arguments from candidates
        local remain_args=$(__nnictl_remain_args ${args})
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        COMPREPLY=($(compgen -W "$remain_args" -- $cur))

        # if this is 3rd arguments, try adding experiment IDs to candidates
        if [[ ${#COMP_WORDS[@]} -eq 4 ]]; then
            if [[ $__nnictl_3rd_expid_cmds =~ " ${COMP_WORDS[1]} " && ${COMP_WORDS[2]} != "list" ]]; then
                local experiments=$(ls ~/nni/experiments 2>/dev/null)
                COMPREPLY+=($(compgen -W "$experiments" -- $cur))
            fi
        fi

    elif [[ ${COMP_WORDS[1]} == "export" ]]; then
        # "export" command is somewhat unique
        if [[ " --type -t " =~ " $last " ]]; then
            COMPREPLY=($(compgen -W "json csv" -- $cur))

        elif [[ " --filename -f " =~ " $last " ]]; then
            # try to detect whether complete CSV file or JSON file
            [[ "$COMP_LINE" =~ "csv" ]] && local export_csv=1
            [[ "$COMP_LINE" =~ "json" ]] && local export_json=1
            if [[ -n $export_csv && -z $export_json ]]; then
                local ext="csv"         # CSV only
            elif [[ -n $export_json && -z $export_csv ]]; then
                local ext="json"        # JSON only
            else
                local ext="@(csv|json)" # both
            fi
            __nnictl_complete_extension "$ext"
        fi

    elif [[ " --trial_id -t " =~ " $last " ]]; then
        # complete trial ID
        if [[ -e ${HOME}/nni/experiments/${COMP_WORDS[2]} ]]; then
            local trials=$(ls -d ~/nni/experiments/${COMP_WORDS[2]}/trials/* 2>/dev/null | grep -o '[^/]*$')
        elif [[ -e "${HOME}/nni/experiments/${COMP_WORDS[3]}" ]]; then
            local trials=$(ls -d ~/nni/experiments/${COMP_WORDS[3]}/trials/* 2>/dev/null | grep -o '[^/]*$')
        else
            local trials=$(ls -d ~/nni/experiments/*/trials/* 2>/dev/null | grep -o '[^/]*$')
        fi
        COMPREPLY=($(compgen -W "$trials" -- $cur))
liuzhe-lz's avatar
liuzhe-lz committed
129

130
131
132
    elif [[ " --config -c " =~ " $last " ]]; then
        # complete YAML file
        __nnictl_complete_extension "@(yml|yaml)"
liuzhe-lz's avatar
liuzhe-lz committed
133

134
135
136
    elif [[ " --filename -f " =~ " $last " ]]; then
        # complete JSON file
        __nnictl_complete_extension "json"
liuzhe-lz's avatar
liuzhe-lz committed
137
138
139
140

    fi
}

141
complete -o nosort -F _nnictl nnictl