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:
|
def generate_kittens_completion() -> None:
|
||||||
from kittens.runner import (
|
from kittens.runner import (
|
||||||
all_kitten_names, get_kitten_cli_docs, get_kitten_wrapper_of,
|
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{'
|
print('plus_open := plus.AddSubCommand(&cli.Command{'
|
||||||
'Name:"open", Group:"Entry points", ArgCompleter: complete_plus_open, ShortDescription: "Open files and URLs"})')
|
'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"')
|
print('k.AddClone("", plus_open).Name = "+open"')
|
||||||
|
|
||||||
# kitty +kitten
|
# kitty +kitten
|
||||||
@ -129,6 +131,7 @@ def generate_completions_for_kitty() -> None:
|
|||||||
print('func init() {')
|
print('func init() {')
|
||||||
print('cli.RegisterExeForCompletion(kitty)')
|
print('cli.RegisterExeForCompletion(kitty)')
|
||||||
print('}')
|
print('}')
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
# rc command wrappers {{{
|
# 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 --start-as ', all_words('minimized', 'maximized', 'fullscreen', 'normal'))
|
||||||
add('kitty -1 ', does_not_have_words('@ls', '@'))
|
add('kitty -1 ', does_not_have_words('@ls', '@'))
|
||||||
add('kitty --directory ', all_words('bin/', 'sub/'))
|
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 -1d', all_words('-1d'))
|
||||||
add('kitty -o a', has_words('allow_remote_control='))
|
add('kitty -o a', has_words('allow_remote_control='))
|
||||||
add('kitty --listen-on ', all_words('unix:', 'tcp:'))
|
add('kitty --listen-on ', all_words('unix:', 'tcp:'))
|
||||||
|
|||||||
@ -209,6 +209,8 @@ func (self *Command) ResetAfterParseArgs() {
|
|||||||
o.reset()
|
o.reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.option_map = nil
|
||||||
|
self.IndexOfFirstArg = 0
|
||||||
self.Args = make([]string, 0, 8)
|
self.Args = make([]string, 0, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,6 +91,7 @@ func GenerateCompletions(args []string) error {
|
|||||||
all_completions := make([]*Completions, 0, 1)
|
all_completions := make([]*Completions, 0, 1)
|
||||||
for _, argv := range all_argv {
|
for _, argv := range all_argv {
|
||||||
all_completions = append(all_completions, root.GetCompletions(argv, init_completions[output_type]))
|
all_completions = append(all_completions, root.GetCompletions(argv, init_completions[output_type]))
|
||||||
|
root.ResetAfterParseArgs()
|
||||||
}
|
}
|
||||||
output, err := output_serializer(all_completions, shell_state)
|
output, err := output_serializer(all_completions, shell_state)
|
||||||
if err == nil {
|
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)
|
cmd.ArgCompleter(completions, word, arg_num)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@ -107,10 +107,10 @@ type Completions struct {
|
|||||||
Groups []*MatchGroup `json:"groups,omitempty"`
|
Groups []*MatchGroup `json:"groups,omitempty"`
|
||||||
Delegate Delegate `json:"delegate,omitempty"`
|
Delegate Delegate `json:"delegate,omitempty"`
|
||||||
|
|
||||||
CurrentCmd *Command
|
CurrentCmd *Command `json:"-"`
|
||||||
AllWords []string // all words passed to parse_args()
|
AllWords []string `json:"-"` // all words passed to parse_args()
|
||||||
CurrentWordIdx int // index of current word in all_words
|
CurrentWordIdx int `json:"-"` // index of current word in all_words
|
||||||
CurrentWordIdxInParent int // index of current word in parents command line 1 for first word after parent
|
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)
|
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 {
|
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 {
|
for i, o := range self.SubCommands {
|
||||||
self.SubCommands[i] = o.Clone(parent)
|
ans.SubCommands[i] = o.Clone(parent)
|
||||||
}
|
}
|
||||||
return &ans
|
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 {
|
func setup_CMD_NAME(parent *cli.Command) *cli.Command {
|
||||||
ans := parent.AddSubCommand(&cli.Command{
|
ans := parent.AddSubCommand(&cli.Command{
|
||||||
Name: "CMD_NAME",
|
Name: "CLI_NAME",
|
||||||
Usage: "ARGSPEC",
|
Usage: "ARGSPEC",
|
||||||
ShortDescription: "SHORT_DESC",
|
ShortDescription: "SHORT_DESC",
|
||||||
HelpText: "LONG_DESC",
|
HelpText: "LONG_DESC",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user