Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pd-ctl: add auto-completion for pd-ctl #2299

Merged
merged 5 commits into from
Mar 31, 2020
Merged

Conversation

hsqlu
Copy link
Contributor

@hsqlu hsqlu commented Mar 29, 2020

UCP: #2170

What problem does this PR solve?

fixed: #2170

What is changed and how it works?

Added new subcommand completion

Usage:
    pd-ctl completion SHELL   

Check List

Tests

  • Manual test (add detailed scripts or steps below)
  • No code
  1. Check shell version and install bash-completion
Qiannan-MBP:bin qiannan$ echo ${BASH_VERSION}
3.2.57(1)-release
Qiannan-MBP:bin qiannan$ brew info bash-completion
bash-completion: stable 1.3 (bottled)
Programmable completion for Bash 3.2
https://salsa.debian.org/debian/bash-completion
Conflicts with:
  bash-completion@2 (because Differing version of same formula)
/usr/local/Cellar/bash-completion/1.3_3 (189 files, 607.9KB) *
  Poured from bottle on 2020-03-29 at 16:27:16
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/bash-completion.rb
==> Caveats
Add the following line to your ~/.bash_profile:
  [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 12,271 (30 days), 39,011 (90 days), 172,085 (365 days)
install-on-request: 11,294 (30 days), 36,102 (90 days), 158,051 (365 days)
build-error: 0 (30 days)

Help info:

Qiannan-MBP:bin qiannan$ pd-ctl completion -h

Output shell completion code for the specified shell (bash).
The shell code must be evaluated to provide interactive
completion of pd-ctl commands.  This can be done by sourcing it from
the .bash_profile.

Usage:
  pd-ctl completion SHELL

Examples:

	# Installing bash completion on macOS using homebrew
	## If running Bash 3.2 included with macOS
	    brew install bash-completion
	## or, if running Bash 4.1+
	    brew install bash-completion@2
	## If you've installed via other means, you may need add the completion to your completion directory
	    pd-ctl completion bash > $(brew --prefix)/etc/bash_completion.d/pd-ctl


	# Installing bash completion on Linux
	## If bash-completion is not installed on Linux, please install the 'bash-completion' package
	## via your distribution's package manager.
	## Load the pd-ctl completion code for bash into the current shell
	    source <(pd-ctl completion bash)
	## Write bash completion code to a file and source if from .bash_profile
		pd-ctl completion bash > ~/completion.bash.inc
		printf "
		# pd-ctl shell completion
		source '$HOME/completion.bash.inc'
		" >> $HOME/.bash_profile
		source $HOME/.bash_profile


Global Flags:
      --cacert string   Path of file that contains list of trusted SSL CAs.
      --cert string     Path of file that contains X509 certificate in PEM format.
  -h, --help            Help message.
      --key string      Path of file that contains X509 key in PEM format.
  -u, --pd string       Address of pd. (default "http://127.0.0.1:2379")

Load the completion code to current shell

source <(pd-ctl completion bash)

Type pd-ctl cl into the current shell, then type tab, it will auto-complete command pd-ctl cluster.

Code changes

  • added new file tools/pd-ctl/pdctl/command/completion_command.go
  • modified file tools/pd-ctl/pdctl/ctl.go

Side effects

N/A

Related changes

nolouch and others added 2 commits March 29, 2020 16:47
* scheduelrs: add load expectations for hot scheudler

Signed-off-by: nolouch <nolouch@gmail.com>
@sre-bot
Copy link
Contributor

sre-bot commented Mar 29, 2020

Thanks for your contribution. If your PR get merged, you will be rewarded 200 points.

@sre-bot sre-bot added the contribution This PR is from a community contributor. label Mar 29, 2020
@CLAassistant
Copy link

CLAassistant commented Mar 29, 2020

CLA assistant check
All committers have signed the CLA.

Signed-off-by: Qiannan Lyu <lvqiannan@gmail.com>
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. @hsqlu , thanks for your contribution.
Would you like to support zsh? like kubectl.

@hsqlu hsqlu force-pushed the auto-completion branch 2 times, most recently from 3fc3cf2 to 492b46a Compare March 30, 2020 22:39
@hsqlu
Copy link
Contributor Author

hsqlu commented Mar 30, 2020

@nolouch Added zsh support, PTAL. Thanks

Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. BTW, is there any way to support auto-completion in interactive mode?

tests/pdctl/completion/completion_test.go Outdated Show resolved Hide resolved
tools/pd-ctl/pdctl/command/completion_command.go Outdated Show resolved Hide resolved
Signed-off-by: Qiannan Lyu <lvqiannan@gmail.com>
@hsqlu
Copy link
Contributor Author

hsqlu commented Mar 31, 2020

LGTM. BTW, is there any way to support auto-completion in interactive mode?

I have no ideas. Any recommended info about that? Thanks

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@rleungx
Copy link
Member

rleungx commented Mar 31, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 31, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 31, 2020

/run-all-tests

@sre-bot sre-bot merged commit 6538321 into tikv:master Mar 31, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 31, 2020

Team hsqlu complete task #2170 and get 200 score, currerent score 250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/can-merge Indicates a PR has been approved by a committer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UCP: Support auto-completion for pd-ctl
5 participants