Various fixes from the completion merge
This commit is contained in:
parent
97716fea8b
commit
262e2fb7a3
@ -47,6 +47,7 @@ def replace(template: str, **kw: str) -> str:
|
||||
# }}}
|
||||
|
||||
|
||||
# Completions {{{
|
||||
def generate_kittens_completion() -> None:
|
||||
from kittens.runner import (
|
||||
all_kitten_names, get_kitten_cli_docs, get_kitten_wrapper_of,
|
||||
@ -109,6 +110,7 @@ def generate_completions_for_kitty() -> None:
|
||||
|
||||
print('plus_open := plus.AddSubCommand(&cli.Command{'
|
||||
'Name:"open", Group:"Entry points", ArgCompleter: complete_plus_open, ShortDescription: "Open files and URLs"})')
|
||||
print('for _, og := range k.OptionGroups { plus_open.OptionGroups = append(plus_open.OptionGroups, og.Clone(plus_open)) }')
|
||||
print('k.AddClone("", plus_open).Name = "+open"')
|
||||
|
||||
# kitty +kitten
|
||||
@ -129,6 +131,7 @@ def generate_completions_for_kitty() -> None:
|
||||
print('func init() {')
|
||||
print('cli.RegisterExeForCompletion(kitty)')
|
||||
print('}')
|
||||
# }}}
|
||||
|
||||
|
||||
# rc command wrappers {{{
|
||||
|
||||
@ -136,7 +136,7 @@ def completion(self: TestCompletion, tdir: str):
|
||||
add('kitty --start-as ', all_words('minimized', 'maximized', 'fullscreen', 'normal'))
|
||||
add('kitty -1 ', does_not_have_words('@ls', '@'))
|
||||
add('kitty --directory ', all_words('bin/', 'sub/'))
|
||||
add('kitty -1d ', all_words('bin/', 'sub/'))
|
||||
add('kitty -1d ', all_words('exe1'))
|
||||
add('kitty -1d', all_words('-1d'))
|
||||
add('kitty -o a', has_words('allow_remote_control='))
|
||||
add('kitty --listen-on ', all_words('unix:', 'tcp:'))
|
||||
|
||||
@ -209,6 +209,8 @@ func (self *Command) ResetAfterParseArgs() {
|
||||
o.reset()
|
||||
}
|
||||
}
|
||||
self.option_map = nil
|
||||
self.IndexOfFirstArg = 0
|
||||
self.Args = make([]string, 0, 8)
|
||||
}
|
||||
|
||||
|
||||
@ -91,6 +91,7 @@ func GenerateCompletions(args []string) error {
|
||||
all_completions := make([]*Completions, 0, 1)
|
||||
for _, argv := range all_argv {
|
||||
all_completions = append(all_completions, root.GetCompletions(argv, init_completions[output_type]))
|
||||
root.ResetAfterParseArgs()
|
||||
}
|
||||
output, err := output_serializer(all_completions, shell_state)
|
||||
if err == nil {
|
||||
|
||||
@ -113,7 +113,7 @@ func complete_word(word string, completions *Completions, only_args_allowed bool
|
||||
}
|
||||
}
|
||||
}
|
||||
if !cmd.SubCommandMustBeFirst && cmd.ArgCompleter != nil {
|
||||
if cmd.SubCommandIsOptional && cmd.ArgCompleter != nil {
|
||||
cmd.ArgCompleter(completions, word, arg_num)
|
||||
}
|
||||
return
|
||||
|
||||
@ -107,10 +107,10 @@ type Completions struct {
|
||||
Groups []*MatchGroup `json:"groups,omitempty"`
|
||||
Delegate Delegate `json:"delegate,omitempty"`
|
||||
|
||||
CurrentCmd *Command
|
||||
AllWords []string // all words passed to parse_args()
|
||||
CurrentWordIdx int // index of current word in all_words
|
||||
CurrentWordIdxInParent int // index of current word in parents command line 1 for first word after parent
|
||||
CurrentCmd *Command `json:"-"`
|
||||
AllWords []string `json:"-"` // all words passed to parse_args()
|
||||
CurrentWordIdx int `json:"-"` // index of current word in all_words
|
||||
CurrentWordIdxInParent int `json:"-"` // index of current word in parents command line 1 for first word after parent
|
||||
|
||||
split_on_equals bool // true if the cmdline is split on = (BASH does this because readline does this)
|
||||
}
|
||||
|
||||
@ -24,9 +24,9 @@ func (self *CommandGroup) HasVisibleSubCommands() bool {
|
||||
}
|
||||
|
||||
func (self *CommandGroup) Clone(parent *Command) *CommandGroup {
|
||||
ans := CommandGroup{Title: self.Title, SubCommands: make([]*Command, 0, len(self.SubCommands))}
|
||||
ans := CommandGroup{Title: self.Title, SubCommands: make([]*Command, len(self.SubCommands))}
|
||||
for i, o := range self.SubCommands {
|
||||
self.SubCommands[i] = o.Clone(parent)
|
||||
ans.SubCommands[i] = o.Clone(parent)
|
||||
}
|
||||
return &ans
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func run_CMD_NAME(cmd *cli.Command, args []string) (return_code int, err error)
|
||||
|
||||
func setup_CMD_NAME(parent *cli.Command) *cli.Command {
|
||||
ans := parent.AddSubCommand(&cli.Command{
|
||||
Name: "CMD_NAME",
|
||||
Name: "CLI_NAME",
|
||||
Usage: "ARGSPEC",
|
||||
ShortDescription: "SHORT_DESC",
|
||||
HelpText: "LONG_DESC",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user