Skip to content

Commit

Permalink
feat: providing subcommand for command completion (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
hung-cybo committed Nov 15, 2022
1 parent 9510c9a commit 0b183d1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,68 @@ with multiple Table fields
,"first",,,"<row id>","20"
```

## Command completion

cli-kintone provides a command-completion feature that enables you to use the **Tab** key to complete a partially entered command.

cli-kintone command completion is now supported only for `bash` and `zsh` shell.

### zsh

To enable it in `zsh`, `cd` to the directory that contains the cli-kintone executable file, then run the below commands:

```shell
# 1. Set PATH environment variables
echo "export PATH=$(pwd):\$PATH" >> ~/.zshrc

# 2. Create and configure a directory to store the completion scripts
mkdir -p ~/.zsh_completion.d/
echo 'fpath=(~/.zsh_completion.d $fpath)' >> ~/.zshrc

# 3. Enable bash-autocomplete feature
echo 'autoload bashcompinit && bashcompinit' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc

# 4. Create command completion script
./cli-kintone completion >> ~/.zsh_completion.d/_cli-kintone

# 5. Reload zsh
source ~/.zshrc
```

### bash

To enable it in `bash`, `cd` to the directory that contains the cli-kintone executable file, then run the below commands:

```shell
# 1. Create command completion script
mkdir -p ~/.bash_completion.d
./cli-kintone completion >> ~/.bash_completion.d/_cli-kintone

# 2. Add command completion script to bash

# For login shell
echo "export PATH=$(pwd):\$PATH" >> ~/.bash_profile
echo 'source ~/.bash_completion.d/_cli-kintone' >> ~/.bash_profile
source ~/.bash_profile

# For non-login shell
echo "export PATH=$(pwd):\$PATH" >> ~/.bashrc
echo 'source ~/.bash_completion.d/_cli-kintone' >> ~/.bashrc
source ~/.bashrc
```

### For Windows OS

For Windows OS, you can use cli-kintone command completion via `bash` on [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install)

Steps:

1. Install Linux on Windows with WSL. Ref: [WSL2](https://learn.microsoft.com/en-us/windows/wsl/install)
2. Open a new Linux Terminal
3. Download and extract executables from the [linux package](https://github.com/kintone/cli-kintone/releases).
4. Run the same commands as [bash section](#bash)

## LICENSE

- [MIT](https://github.com/kintone/cli-kintone/blob/main/LICENSE)
7 changes: 6 additions & 1 deletion src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import yargs from "yargs";
import { recordCommand } from "./record";

// eslint-disable-next-line no-unused-expressions
yargs.command(recordCommand).demandCommand().strict().help().argv;
yargs
.completion("completion")
.command(recordCommand)
.demandCommand()
.strict()
.help().argv;

0 comments on commit 0b183d1

Please sign in to comment.