feat(spec): change priority
This commit is contained in:
+27
-25
@@ -51,6 +51,8 @@ func Register(s *Spec) {
|
|||||||
// And tokenizer helps us to detect white space like we can't know if you are typing "git-lfs"
|
// And tokenizer helps us to detect white space like we can't know if you are typing "git-lfs"
|
||||||
// or "git" to show the suggestions, without it, if you type "git " (with white space), it still shows
|
// or "git" to show the suggestions, without it, if you type "git " (with white space), it still shows
|
||||||
// suggestion for "git-lfs"
|
// suggestion for "git-lfs"
|
||||||
|
//
|
||||||
|
// priority: file/dir -> subcommands -> options
|
||||||
func Lookup(input string) []Suggestion {
|
func Lookup(input string) []Suggestion {
|
||||||
tokens := tokenize(input)
|
tokens := tokenize(input)
|
||||||
if len(tokens) == 0 {
|
if len(tokens) == 0 {
|
||||||
@@ -109,31 +111,7 @@ func Lookup(input string) []Suggestion {
|
|||||||
|
|
||||||
results := []Suggestion{}
|
results := []Suggestion{}
|
||||||
|
|
||||||
// suggest subcommands
|
// file/dir
|
||||||
for _, sub := range currentSubs {
|
|
||||||
if partial == "" || hasPrefix(sub.Name, partial) {
|
|
||||||
results = append(results, Suggestion{
|
|
||||||
Cmd: prefix + " " + sub.Name,
|
|
||||||
Desc: sub.Description,
|
|
||||||
Icon: root,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// suggest options if typing with '-'
|
|
||||||
if partial == "" || partial[0] == '-' {
|
|
||||||
for _, opt := range currentOpts {
|
|
||||||
if partial == "" || hasPrefix(opt.Name, partial) {
|
|
||||||
results = append(results, Suggestion{
|
|
||||||
Cmd: prefix + " " + opt.Name,
|
|
||||||
Desc: opt.Description,
|
|
||||||
Icon: root,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// use generator if available
|
|
||||||
if currentGen != nil {
|
if currentGen != nil {
|
||||||
genResults := currentGen(tokens[:depth], prefix, partial)
|
genResults := currentGen(tokens[:depth], prefix, partial)
|
||||||
for _, g := range genResults {
|
for _, g := range genResults {
|
||||||
@@ -150,6 +128,30 @@ func Lookup(input string) []Suggestion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// subcommands
|
||||||
|
for _, sub := range currentSubs {
|
||||||
|
if partial == "" || hasPrefix(sub.Name, partial) {
|
||||||
|
results = append(results, Suggestion{
|
||||||
|
Cmd: prefix + " " + sub.Name,
|
||||||
|
Desc: sub.Description,
|
||||||
|
Icon: root,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// options
|
||||||
|
if partial == "" || (len(partial) > 0 && partial[0] == '-') {
|
||||||
|
for _, opt := range currentOpts {
|
||||||
|
if partial == "" || hasPrefix(opt.Name, partial) {
|
||||||
|
results = append(results, Suggestion{
|
||||||
|
Cmd: prefix + " " + opt.Name,
|
||||||
|
Desc: opt.Description,
|
||||||
|
Icon: root,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user