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

Support bash and zsh completion #606

Merged
merged 1 commit into from
Jul 16, 2020
Merged

Conversation

yeya24
Copy link
Contributor

@yeya24 yeya24 commented Jul 15, 2020

Signed-off-by: Ben Ye yb532204897@gmail.com

What problem does this PR solve?

Fixes #73

What is changed and how it works?

Add a tiup completion [bash | zsh] command.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change
  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

@CLAassistant
Copy link

CLAassistant commented Jul 15, 2020

CLA assistant check
All committers have signed the CLA.

@yeya24 yeya24 force-pushed the support-completion branch 2 times, most recently from 8d71e20 to a5de6e3 Compare July 15, 2020 23:31
@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2020

Codecov Report

Merging #606 into master will decrease coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #606      +/-   ##
==========================================
- Coverage   50.95%   50.75%   -0.20%     
==========================================
  Files         219      220       +1     
  Lines       15951    16102     +151     
==========================================
+ Hits         8128     8173      +45     
- Misses       6684     6786     +102     
- Partials     1139     1143       +4     
Flag Coverage Δ
#coverage 50.75% <ø> (-0.20%) ⬇️
Impacted Files Coverage Δ
...c/github.com/pingcap/tiup/pkg/cluster/api/pdapi.go 60.24% <0.00%> (-1.87%) ⬇️
go/src/github.com/pingcap/tiup/cmd/list.go 40.55% <0.00%> (-0.70%) ⬇️
...ub.com/pingcap/tiup/pkg/repository/clone_mirror.go 0.00% <0.00%> (ø)
...om/pingcap/tiup/pkg/cluster/embed/autogen_pkger.go 100.00% <0.00%> (ø)
go/src/github.com/pingcap/tiup/cmd/completion.go 21.37% <0.00%> (ø)
...b.com/pingcap/tiup/pkg/repository/v1_repository.go 66.32% <0.00%> (+0.41%) ⬆️
go/src/github.com/pingcap/tiup/cmd/root.go 60.86% <0.00%> (+0.43%) ⬆️
...pingcap/tiup/pkg/repository/v1manifest/manifest.go 54.14% <0.00%> (+2.82%) ⬆️
...om/pingcap/tiup/pkg/repository/v1manifest/types.go 80.00% <0.00%> (+5.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 042b077...3894e0d. Read the comment docs.

" >> $HOME/.bash_profile
source $HOME/.bash_profile


Copy link
Contributor

Choose a reason for hiding this comment

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

Does here need two blank lines? can we just retain one blank line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

case "zsh":
return genCompletionZsh(os.Stdout, cmd.Parent())
default:
return errors.New("Unsupported shell type " + args[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

The error should begin with the lower-case according to Golang idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@lonng
Copy link
Contributor

lonng commented Jul 16, 2020

@yeya24 Awesome works. is there any way for components completion?

e.g:

$ tiup <TAB>
cluster playground ....

@lonng lonng added type/enhancement Categorizes issue or PR as related to an enhancement. category/contribution labels Jul 16, 2020
Signed-off-by: Ben Ye <yb532204897@gmail.com>
@yeya24
Copy link
Contributor Author

yeya24 commented Jul 16, 2020

@yeya24 Awesome works. is there any way for components completion?

e.g:

$ tiup <TAB>
cluster playground ....

To be honest I don't know how to support that.

@yeya24
Copy link
Contributor Author

yeya24 commented Jul 16, 2020

@lonng Can I ask why the CI test failed? Is it related to this change?

Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 16, 2020
@lonng lonng merged commit 716860a into pingcap:master Jul 16, 2020
@lucklove
Copy link
Member

Can I ask why the CI test failed? Is it related to this change?

@yeya24 Our global CDN doesn't work very well at this time, so the CI may fail on the network issue (and retry will success). We are trying to fix this.

@yeya24 yeya24 deleted the support-completion branch October 28, 2020 16:44
yahonda added a commit to yahonda/yatico that referenced this pull request Aug 27, 2021
make bash-autocompletion works for tiup components(ie. cluster, br).
Current TiUP native bash-autocompletion does not support them

Refer pingcap/tiup#606

- `cluster` and `br` compoments supported, others may be coming

- Usage

```
$ source /path/to/tiup_completion.bash
$ tiup <TAB>
bench           cdc             client          completion      dm              env             help            list            pd-recover      status          tidb            uninstall
br              clean           cluster         ctl             dmctl           errdoc          install         mirror          playground      telemetry       tidb-lightning  update
$ tiup c<TAB>
cdc         clean       client      cluster     completion  ctl
$ tiup cluster <TAB>
audit        clean        destroy      display      enable       import       patch        reload       replay       scale-in     start        template
check        deploy       disable      edit-config  help         list         prune        rename       restart      scale-out    stop         upgrade
```

Thanks to
https://stackoverflow.com/questions/17879322/how-do-i-autocomplete-nested-multi-level-subcommands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1. type/enhancement Categorizes issue or PR as related to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UCP: Support zsh/bash auto-completion for TiUP
6 participants