Unverified Commit 98a49b18 authored by Junwei Sun's avatar Junwei Sun Committed by GitHub
Browse files

Update bash-completion (#2857)

parent bc71a0d6
...@@ -11,7 +11,7 @@ This is the PyPI build and upload tool for NNI project. ...@@ -11,7 +11,7 @@ This is the PyPI build and upload tool for NNI project.
Ubuntu 16.04 LTS Ubuntu 16.04 LTS
make make
wget wget
Python >= 3.5 Python >= 3.6
Pip Pip
Node.js Node.js
Yarn Yarn
...@@ -45,7 +45,7 @@ This is the PyPI build and upload tool for NNI project. ...@@ -45,7 +45,7 @@ This is the PyPI build and upload tool for NNI project.
``` ```
Windows 10 Windows 10
powershell powershell
Python >= 3.5 Python >= 3.6
Pip Pip
Yarn Yarn
``` ```
......
# Auto Completion for nnictl Commands
NNI's command line tool __nnictl__ support auto-completion, i.e., you can complete a nnictl command by pressing the `tab` key.
For example, if the current command is
```
nnictl cre
```
By pressing the `tab` key, it will be completed to
```
nnictl create
```
For now, auto-completion will not be enabled by default if you install NNI through `pip`, and it only works on Linux with bash shell. If you want to enable this feature on your computer, please refer to the following steps:
### Step 1. Download `bash-completion`
```
cd ~
wget https://raw.githubusercontent.com/microsoft/nni/{nni-version}/tools/bash-completion
```
Here, {nni-version} should by replaced by the version of NNI, e.g., `master`, `v1.9`. You can also check the latest `bash-completion` script [here](https://github.com/microsoft/nni/blob/master/tools/bash-completion).
### Step 2. Install the script
If you are running a root account and want to install this script for all the users
```
install -m644 ~/bash-completion /usr/share/bash-completion/completions/nnictl
```
If you just want to install this script for your self
```
mkdir -p ~/.bash_completion.d
install -m644 ~/bash-completion ~/.bash_completion.d/nnictl
echo '[[ -f ~/.bash_completion.d/nnictl ]] && source ~/.bash_completion.d/nnictl' >> ~/.bash_completion
```
### Step 3. Reopen your terminal
Reopen your terminal and you should be able to use the auto-completion feature. Enjoy!
### Step 4. Uninstall
If you want to uninstall this feature, just revert the changes in the steps above.
...@@ -13,3 +13,4 @@ Different from the tutorials and examples in the rest of the document which show ...@@ -13,3 +13,4 @@ Different from the tutorials and examples in the rest of the document which show
Feature Engineering <feature_engineering> Feature Engineering <feature_engineering>
Performance measurement, comparison and analysis <perf_compare> Performance measurement, comparison and analysis <perf_compare>
Use NNI on Google Colab <NNI_colab_support> Use NNI on Google Colab <NNI_colab_support>
Auto Completion for nnictl Commands <AutoCompletion>
...@@ -295,7 +295,7 @@ Debug mode will disable version check function in Trialkeeper. ...@@ -295,7 +295,7 @@ Debug mode will disable version check function in Trialkeeper.
> update experiment's trial num > update experiment's trial num
```bash ```bash
nnictl update trialnum --id [experiment_id] --value [trial_num] nnictl update trialnum [experiment_id] --value [trial_num]
``` ```
<a name="trial"></a> <a name="trial"></a>
...@@ -347,7 +347,7 @@ Debug mode will disable version check function in Trialkeeper. ...@@ -347,7 +347,7 @@ Debug mode will disable version check function in Trialkeeper.
> kill trail job > kill trail job
```bash ```bash
nnictl trial [trial_id] --experiment [experiment_id] nnictl trial kill [experiment_id] --trial_id [trial_id]
``` ```
<a name="top"></a> <a name="top"></a>
...@@ -704,6 +704,21 @@ Debug mode will disable version check function in Trialkeeper. ...@@ -704,6 +704,21 @@ Debug mode will disable version check function in Trialkeeper.
### Manage webui ### Manage webui
* __nnictl webui url__ * __nnictl webui url__
* Description
Show an experiment's webui url
* Usage
```bash
nnictl webui url [options]
```
* Options
|Name, shorthand|Required|Default|Description|
|------|------|------ |------|
|id| False| |Experiment ID|
<a name="tensorboard"></a> <a name="tensorboard"></a>
### Manage tensorboard ### Manage tensorboard
......
...@@ -27,6 +27,9 @@ python -m pip install --upgrade nni ...@@ -27,6 +27,9 @@ python -m pip install --upgrade nni
```eval_rst ```eval_rst
.. Note:: For the system requirements of NNI, please refer to :doc:`Install NNI on Linux & Mac <InstallationLinux>` or :doc:`Windows <InstallationWin>`. .. Note:: For the system requirements of NNI, please refer to :doc:`Install NNI on Linux & Mac <InstallationLinux>` or :doc:`Windows <InstallationWin>`.
``` ```
### Enable NNI Command-line Auto-Completion (Optional)
After the installation, you may want to enable the auto-completion feature for __nnictl__ commands. Please refer to this [tutorial](../CommunitySharings/AutoCompletion.md).
## "Hello World" example on MNIST ## "Hello World" example on MNIST
......
# list of commands/arguments # list of commands/arguments
__nnictl_cmds="create resume view update stop trial experiment platform import export webui config log package tensorboard top" __nnictl_cmds="create resume view update stop trial experiment platform webui config log package tensorboard top ss_gen --version"
__nnictl_create_cmds="--config --port --debug --watch" __nnictl_create_cmds="--config --port --debug --foreground"
__nnictl_resume_cmds="--port --debug --watch" __nnictl_resume_cmds="--port --debug --foreground"
__nnictl_view_cmds="--port" __nnictl_view_cmds="--port"
__nnictl_update_cmds="searchspace concurrency duration trialnum" __nnictl_update_cmds="searchspace concurrency duration trialnum"
__nnictl_update_searchspace_cmds="--filename" __nnictl_update_searchspace_cmds="--filename"
...@@ -9,30 +9,34 @@ __nnictl_update_concurrency_cmds="--value" ...@@ -9,30 +9,34 @@ __nnictl_update_concurrency_cmds="--value"
__nnictl_update_duration_cmds="--value" __nnictl_update_duration_cmds="--value"
__nnictl_update_trialnum_cmds="--value" __nnictl_update_trialnum_cmds="--value"
__nnictl_stop_cmds="--port --all" __nnictl_stop_cmds="--port --all"
__nnictl_trial_cmds="ls kill codegen" __nnictl_trial_cmds="ls kill"
__nnictl_trial_ls_cmds="--head --tail"
__nnictl_trial_kill_cmds="--trial_id" __nnictl_trial_kill_cmds="--trial_id"
__nnictl_trial_codegen_cmds="--trial_id" __nnictl_experiment_cmds="show status list delete export import save load"
__nnictl_experiment_cmds="show status list delete"
__nnictl_experiment_list_cmds="--all" __nnictl_experiment_list_cmds="--all"
__nnictl_experiment_delete_cmds="--all" __nnictl_experiment_delete_cmds="--all"
__nnictl_experiment_export_cmds="--filename --type --intermediate"
__nnictl_experiment_import_cmds="--filename"
__nnictl_experiment_save_cmds="--path --saveCodeDir"
__nnictl_experiment_load_cmds="--path --codeDir --logDir"
__nnictl_platform_cmds="clean" __nnictl_platform_cmds="clean"
__nnictl_platform_clean_cmds="--config" __nnictl_platform_clean_cmds="--config"
__nnictl_import_cmds="--filename"
__nnictl_export_cmds="--type --filename"
__nnictl_webui_cmds="url" __nnictl_webui_cmds="url"
__nnictl_config_cmds="show" __nnictl_config_cmds="show"
__nnictl_log_cmds="stdout stderr trial" __nnictl_log_cmds="stdout stderr trial"
__nnictl_log_stdout_cmds="--tail --head --path" __nnictl_log_stdout_cmds="--tail --head --path"
__nnictl_log_stderr_cmds="--tail --head --path" __nnictl_log_stderr_cmds="--tail --head --path"
__nnictl_log_trial_cmds="--trial_id" __nnictl_log_trial_cmds="--trial_id"
__nnictl_package_cmds="install show" __nnictl_package_cmds="install show list uninstall"
__nnictl_package_install_cmds="--name" __nnictl_package_install_cmds="--name"
__nnictl_package_list_cmds="--all"
__nnictl_tensorboard_cmds="start stop" __nnictl_tensorboard_cmds="start stop"
__nnictl_tensorboard_start_cmds="--trial_id --port" __nnictl_tensorboard_start_cmds="--trial_id --port"
__nnictl_top_cmds="--time" __nnictl_top_cmds="--time"
__nnictl_ss_gen_cmds="--trial_command --trial_dir --file"
# list of commands that accept an experiment ID as second argument # list of commands that accept an experiment ID as second argument
__nnictl_2nd_expid_cmds=" resume view stop import export " __nnictl_2nd_expid_cmds=" resume view stop top "
# list of commands that accept an experiment ID as third argument # list of commands that accept an experiment ID as third argument
__nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard " __nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard "
...@@ -41,10 +45,12 @@ __nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard " ...@@ -41,10 +45,12 @@ __nnictl_3rd_expid_cmds=" update trial experiment webui config log tensorboard "
__nnictl_remain_args() __nnictl_remain_args()
{ {
local ret=${!1} # ret = $__nnictl_xxx_cmds local ret=${!1} # ret = $__nnictl_xxx_cmds
# for arg in COMP_WORDS[:-1]: # prevent that "--trial_id" changes to "--_id" in this situation: "nnictl trial kill --trial_id"
for arg in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}"; do if [[ ${ret} != "--trial_id" ]]; then
local ret=${ret/$arg/} # remove it from $ret for arg in "${COMP_WORDS[@]::${#COMP_WORDS[@]}-1}"; do
done local ret=${ret/$arg/} # remove it from $ret
done
fi
echo $ret echo $ret
} }
...@@ -63,9 +69,8 @@ _nnictl() ...@@ -63,9 +69,8 @@ _nnictl()
{ {
local cur=${COMP_WORDS[-1]} local cur=${COMP_WORDS[-1]}
local last=${COMP_WORDS[-2]} local last=${COMP_WORDS[-2]}
if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then if [[ ${#COMP_WORDS[@]} -eq 2 ]]; then
# completing frst argument from __nnictl_cmds # completing first argument from __nnictl_cmds
COMPREPLY=($(compgen -W "$__nnictl_cmds" -- "${COMP_WORDS[1]}")) COMPREPLY=($(compgen -W "$__nnictl_cmds" -- "${COMP_WORDS[1]}"))
elif [[ ${#COMP_WORDS[@]} -eq 3 ]]; then elif [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
...@@ -79,11 +84,11 @@ _nnictl() ...@@ -79,11 +84,11 @@ _nnictl()
COMPREPLY+=($(compgen -W "$experiments" -- $cur)) COMPREPLY+=($(compgen -W "$experiments" -- $cur))
fi fi
elif [[ $last != -* || $last == --debug ]]; then elif [[ $last != -* || $last == --debug || $last == --foreground || $last == --intermediate || $last == --all ]]; then
# last argument does not starts with "-", so this one is likely to be "--xxx" # last argument does not starts with "-", so this one is likely to be "--xxx"
local args=__nnictl_${COMP_WORDS[1]}_${COMP_WORDS[2]}_cmds local args=__nnictl_${COMP_WORDS[1]}_${COMP_WORDS[2]}_cmds
if [[ $args =~ "-" || -z ${!args} ]]; then if [[ $args =~ "-" || $__nnictl_2nd_expid_cmds =~ " ${COMP_WORDS[1]} " ]]; then
# the second argument starts with "-", use __nnictl_${FirstArg}_cmds # the second argument starts with "-" or is an experiment id, use __nnictl_${FirstArg}_cmds
local args=__nnictl_${COMP_WORDS[1]}_cmds local args=__nnictl_${COMP_WORDS[1]}_cmds
fi fi
# remove already set arguments from candidates # remove already set arguments from candidates
...@@ -93,12 +98,12 @@ _nnictl() ...@@ -93,12 +98,12 @@ _nnictl()
# if this is 3rd arguments, try adding experiment IDs to candidates # if this is 3rd arguments, try adding experiment IDs to candidates
if [[ ${#COMP_WORDS[@]} -eq 4 ]]; then if [[ ${#COMP_WORDS[@]} -eq 4 ]]; then
if [[ $__nnictl_3rd_expid_cmds =~ " ${COMP_WORDS[1]} " && ${COMP_WORDS[2]} != "list" ]]; then if [[ $__nnictl_3rd_expid_cmds =~ " ${COMP_WORDS[1]} " && ${COMP_WORDS[2]} != "list" ]]; then
local experiments=$(ls ~/nni/experiments 2>/dev/null) local experiments=$(ls ~/nni-experiments 2>/dev/null)
COMPREPLY+=($(compgen -W "$experiments" -- $cur)) COMPREPLY+=($(compgen -W "$experiments" -- $cur))
fi fi
fi fi
elif [[ ${COMP_WORDS[1]} == "export" ]]; then elif [[ ${COMP_WORDS[2]} == "export" ]]; then
# "export" command is somewhat unique # "export" command is somewhat unique
if [[ " --type -t " =~ " $last " ]]; then if [[ " --type -t " =~ " $last " ]]; then
COMPREPLY=($(compgen -W "json csv" -- $cur)) COMPREPLY=($(compgen -W "json csv" -- $cur))
...@@ -117,14 +122,14 @@ _nnictl() ...@@ -117,14 +122,14 @@ _nnictl()
__nnictl_complete_extension "$ext" __nnictl_complete_extension "$ext"
fi fi
elif [[ " --trial_id -t " =~ " $last " ]]; then elif [[ " --trial_id -T " =~ " $last " ]]; then
# complete trial ID # complete trial ID
if [[ -e ${HOME}/nni/experiments/${COMP_WORDS[2]} ]]; then if [[ -e ${HOME}/nni-experiments/${COMP_WORDS[2]} ]]; then
local trials=$(ls -d ~/nni/experiments/${COMP_WORDS[2]}/trials/* 2>/dev/null | grep -o '[^/]*$') local trials=$(ls -d ~/nni-experiments/${COMP_WORDS[2]}/trials/* 2>/dev/null | grep -o '[^/]*$')
elif [[ -e "${HOME}/nni/experiments/${COMP_WORDS[3]}" ]]; then elif [[ -e "${HOME}/nni-experiments/${COMP_WORDS[3]}" ]]; then
local trials=$(ls -d ~/nni/experiments/${COMP_WORDS[3]}/trials/* 2>/dev/null | grep -o '[^/]*$') local trials=$(ls -d ~/nni-experiments/${COMP_WORDS[3]}/trials/* 2>/dev/null | grep -o '[^/]*$')
else else
local trials=$(ls -d ~/nni/experiments/*/trials/* 2>/dev/null | grep -o '[^/]*$') local trials=$(ls -d ~/nni-experiments/*/trials/* 2>/dev/null | grep -o '[^/]*$')
fi fi
COMPREPLY=($(compgen -W "$trials" -- $cur)) COMPREPLY=($(compgen -W "$trials" -- $cur))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment