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

add pdctl interactive mode autocomplete #2785

Merged
merged 20 commits into from
Aug 20, 2020
Merged

add pdctl interactive mode autocomplete #2785

merged 20 commits into from
Aug 20, 2020

Conversation

jiashiwen
Copy link
Contributor

@jiashiwen jiashiwen commented Aug 18, 2020

What problem does this PR solve?

#2299

What is changed and how it works?

interactive mode ,use "tab" to auto complete command and flags

Check List

Tests

  • Manual test (add detailed scripts or steps below)

run pd-ctl as interactive mode
press 'tab' show command will be used

Code changes

add new varable

readlinecompleter *readline.PrefixCompleter

add new func

func GenCompleter(cmd *cobra.Command) []readline.PrefixCompleterInterface {
	pc := []readline.PrefixCompleterInterface{}
	if len(cmd.Commands()) != 0 {
		for _, v := range cmd.Commands() {
			// fmt.Println(strings.Split(v.Use, " ")[0]
			if v.HasFlags() {
				flagspc := []readline.PrefixCompleterInterface{}

				flaguseages := strings.Split(strings.Trim(v.Flags().FlagUsages(), " "), "\n")

				for i := 0; i < len(flaguseages)-1; i++ {
					flagspc = append(flagspc, readline.PcItem(strings.Split(strings.Trim(flaguseages[i], " "), " ")[0]))
				}
				flagspc = append(flagspc, GenCompleter(v)...)
				pc = append(pc, readline.PcItem(strings.Split(v.Use, " ")[0], flagspc...))

			} else {
				pc = append(pc, readline.PcItem(strings.Split(v.Use, " ")[0], GenCompleter(v)...))
			}
		}
	}
	return pc
}

func getMainCmd add new expression

readlinecompleter = readline.NewPrefixCompleter(GenCompleter(rootCmd)...)

func loop() add

AutoComplete: readlinecompleter,

Release note

Signed-off-by: jiashiwen <jiashiwen126@126.com>
Signed-off-by: jiashiwen <jiashiwen126@126.com>
@ti-srebot ti-srebot added the contribution This PR is from a community contributor. label Aug 18, 2020
@JmPotato
Copy link
Member

/rebuild

Copy link
Contributor

@Yisaer Yisaer left a comment

Choose a reason for hiding this comment

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

The rest LGTM

tools/pd-ctl/pdctl/ctl_test.go Show resolved Hide resolved
tools/pd-ctl/pdctl/ctl_test.go Outdated Show resolved Hide resolved
tools/pd-ctl/pdctl/ctl_test.go Outdated Show resolved Hide resolved
Signed-off-by: jiashiwen <jiashiwen126@126.com>
@rleungx
Copy link
Member

rleungx commented Aug 19, 2020

The PR description is not very clear, would you like to format it?

@jiashiwen
Copy link
Contributor Author

description

how to do?

Copy link
Contributor

@Yisaer Yisaer left a comment

Choose a reason for hiding this comment

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

The rest LGTM

tools/pd-ctl/pdctl/ctl_test.go Outdated Show resolved Hide resolved
tools/pd-ctl/pdctl/ctl.go Outdated Show resolved Hide resolved
@jiashiwen
Copy link
Contributor Author

idc-jenkins-ci/test error,but the unit test not my code

@JmPotato
Copy link
Member

/rebuild

Copy link
Contributor

@Yisaer Yisaer 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
Copy link
Contributor

@Yisaer,Thanks for your review. However, LGTM is restricted to Reviewers or higher roles.See the corresponding SIG page for more information. Related SIGs: scheduling(slack).

@Yisaer Yisaer requested a review from rleungx August 20, 2020 03:40
@Yisaer Yisaer requested a review from JmPotato August 20, 2020 03:40
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.

The rest LGTM

tools/pd-ctl/pdctl/ctl_test.go Outdated Show resolved Hide resolved
Signed-off-by: jiashiwen <jiashiwen126@126.com>
@howardlau1999
Copy link
Contributor

LGTM

@ti-srebot
Copy link
Contributor

@howardlau1999,Thanks for your review. However, LGTM is restricted to Reviewers or higher roles.See the corresponding SIG page for more information. Related SIGs: scheduling(slack).

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.

@nolouch
Copy link
Contributor

nolouch commented Aug 20, 2020

/merge

@ti-srebot
Copy link
Contributor

@nolouch Oops! This PR requires at least 2 LGTMs to merge. The current number of LGTM is 0.

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 20, 2020
@nolouch nolouch merged commit c030847 into tikv:master Aug 20, 2020
ZenoTan pushed a commit to ZenoTan/pd that referenced this pull request Aug 24, 2020
* add pdctl interactive mode autocomplete

Signed-off-by: jiashiwen <jiashiwen126@126.com>
Signed-off-by: ZenoTan <zenotan1998@gmail.com>
jyz0309 pushed a commit to jyz0309/pd that referenced this pull request Aug 24, 2020
* add pdctl interactive mode autocomplete

Signed-off-by: jiashiwen <jiashiwen126@126.com>
jyz0309 pushed a commit to jyz0309/pd that referenced this pull request Aug 24, 2020
* add pdctl interactive mode autocomplete

Signed-off-by: jiashiwen <jiashiwen126@126.com>
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/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants