From 6accbf734f2d93138bcc0f43cf944b8835f20783 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Sat, 12 Aug 2023 06:02:19 +0200 Subject: [PATCH 1/8] Fixes related to readline ones --- commands/readline/bind.go | 5 ++--- commands/readline/commands.go | 3 +-- commands/readline/completers.go | 5 ++--- commands/readline/export.go | 3 +-- commands/readline/set.go | 5 ++--- tab-completer.go | 8 +++++--- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/commands/readline/bind.go b/commands/readline/bind.go index 2af32de..a370360 100644 --- a/commands/readline/bind.go +++ b/commands/readline/bind.go @@ -6,11 +6,10 @@ import ( "os" "strings" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/reeflective/readline" "github.com/reeflective/readline/inputrc" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) // Bind returns a command named `bind`, for manipulating readline keymaps and bindings. diff --git a/commands/readline/commands.go b/commands/readline/commands.go index cb89c6c..e3ec1bf 100644 --- a/commands/readline/commands.go +++ b/commands/readline/commands.go @@ -1,9 +1,8 @@ package readline import ( - "github.com/spf13/cobra" - "github.com/reeflective/readline" + "github.com/spf13/cobra" ) // Commands returns a command named `readline`, with subcommands dedicated diff --git a/commands/readline/completers.go b/commands/readline/completers.go index fa3ee06..121ab72 100644 --- a/commands/readline/completers.go +++ b/commands/readline/completers.go @@ -21,11 +21,10 @@ package readline import ( "fmt" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/reeflective/readline" "github.com/reeflective/readline/inputrc" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) func completeKeymaps(sh *readline.Shell, _ *cobra.Command) carapace.Action { diff --git a/commands/readline/export.go b/commands/readline/export.go index 67f70e9..0030f15 100644 --- a/commands/readline/export.go +++ b/commands/readline/export.go @@ -23,10 +23,9 @@ import ( "sort" "strings" - "github.com/spf13/cobra" - "github.com/reeflective/readline" "github.com/reeflective/readline/inputrc" + "github.com/spf13/cobra" ) const ( diff --git a/commands/readline/set.go b/commands/readline/set.go index ee0a2da..39c1e51 100644 --- a/commands/readline/set.go +++ b/commands/readline/set.go @@ -5,14 +5,13 @@ import ( "strconv" "strings" + "github.com/reeflective/readline" + "github.com/reeflective/readline/inputrc" "github.com/rsteube/carapace" "github.com/rsteube/carapace/pkg/style" "github.com/spf13/cobra" "golang.org/x/exp/maps" "golang.org/x/exp/slices" - - "github.com/reeflective/readline" - "github.com/reeflective/readline/inputrc" ) var ( diff --git a/tab-completer.go b/tab-completer.go index 5418bdf..fe07e7e 100644 --- a/tab-completer.go +++ b/tab-completer.go @@ -28,9 +28,6 @@ func (c *Console) complete(line []rune, pos int) readline.Completions { // (we currently need those two dummies for avoiding a panic). args = append([]string{"examples", "_carapace"}, args...) - // Regenerate a new instance of the commands. - // menu.hideFilteredCommands(cmd) - // Call the completer with our current command context. values, meta := carapace.Complete(menu.Command, args, c.completeCommands(menu)) @@ -58,6 +55,11 @@ func (c *Console) complete(line []rune, pos int) readline.Completions { comps = comps.NoSpace([]rune(meta.Nospace.String())...) } + // Other status/error messages + for _, msg := range meta.Messages.Get() { + comps = comps.Merge(readline.CompleteMessage(msg)) + } + // If we have a quote/escape sequence unaccounted // for in our completions, add it to all of them. if prefix != "" { From 7834a6a682fd86ba9a5a4d767400fd2bb0b90d9a Mon Sep 17 00:00:00 2001 From: maxlandon Date: Tue, 15 Aug 2023 06:23:10 +0200 Subject: [PATCH 2/8] Fix many problems of quoted completion --- tab-completer.go | 149 ++++++++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 59 deletions(-) diff --git a/tab-completer.go b/tab-completer.go index fe07e7e..f7252db 100644 --- a/tab-completer.go +++ b/tab-completer.go @@ -7,6 +7,7 @@ import ( "os" "regexp" "strings" + "unicode" "unicode/utf8" "github.com/reeflective/readline" @@ -20,9 +21,7 @@ func (c *Console) complete(line []rune, pos int) readline.Completions { // Split the line as shell words, only using // what the right buffer (up to the cursor) - rbuffer := line[:pos] - args, prefix := splitArgs(rbuffer) - args = sanitizeArgs(rbuffer, args) + args, prefixComp, prefixLine := splitArgs(line, pos) // Prepare arguments for the carapace completer // (we currently need those two dummies for avoiding a panic). @@ -62,64 +61,12 @@ func (c *Console) complete(line []rune, pos int) readline.Completions { // If we have a quote/escape sequence unaccounted // for in our completions, add it to all of them. - if prefix != "" { - comps = comps.Prefix(prefix) - } + comps = comps.Prefix(prefixComp) + comps.PREFIX = prefixLine return comps } -func splitArgs(line []rune) (args []string, prefix string) { - // Remove all colors from the string - line = []rune(strip(string(line))) - - // Split the line as shellwords, return them if all went fine. - args, remain, err := splitCompWords(string(line)) - if err == nil { - return args, remain - } - - // If we had an error, it's because we have an unterminated quote/escape sequence. - // In this case we split the remainder again, as the completer only ever considers - // words as space-separated chains of characters. - if errors.Is(err, errUnterminatedDoubleQuote) { - remain = strings.Trim(remain, "\"") - prefix = "\"" - } else if errors.Is(err, errUnterminatedSingleQuote) { - remain = strings.Trim(remain, "'") - prefix = "'" - } - - args = append(args, strings.Split(remain, " ")...) - - return -} - -func sanitizeArgs(rbuffer []rune, args []string) (sanitized []string) { - // Like in classic system shells, we need to add an empty - // argument if the last character is a space: the args - // returned from the previous call don't account for it. - if strings.HasSuffix(string(rbuffer), " ") || len(args) == 0 { - args = append(args, "") - } else if strings.HasSuffix(string(rbuffer), "\n") { - args = append(args, "") - } - - if len(args) == 0 { - return - } - - sanitized = args[:len(args)-1] - last := args[len(args)-1] - - // The last word should not comprise newlines. - last = strings.ReplaceAll(last, "\n", " ") - last = strings.ReplaceAll(last, "\\ ", " ") - sanitized = append(sanitized, last) - - return sanitized -} - // Regenerate commands and apply any filters. func (c *Console) completeCommands(menu *Menu) func() { commands := func() { @@ -177,6 +124,91 @@ func (c *Console) defaultStyleConfig() { style.Set("carapace.FlagOptArg", "bright-white") } +// splitArgs splits the line in valid words, prepares them in various ways before calling +// the completer with them, and also determines which parts of them should be used as +// prefixes, in the completions and/or in the line. +func splitArgs(line []rune, pos int) (args []string, prefixComp, prefixLine string) { + line = line[:pos] + + // Remove all colors from the string + line = []rune(strip(string(line))) + + // Split the line as shellwords, return them if all went fine. + args, remain, err := splitCompWords(string(line)) + + // We might have either no error and args, or no error and + // the cursor ready to complete a new word (last character + // in line is a space). + // In some of those cases we append a single dummy argument + // for the completer to understand we want a new word comp. + mustComplete, args := mustComplete(line, args, remain, err) + if mustComplete { + return sanitizeArgs(args), remain, remain + } + + // The remainder is everything following the open charater. + // Pass it as is to the carapace completion engine. + args = append(args, remain) + + // But the completion candidates themselves might need slightly + // different prefixes, for an optimal completion experience. + prefixComp, prefixLine = adjustQuotedPrefix(remain, err) + + return sanitizeArgs(args), prefixComp, prefixLine +} + +func mustComplete(line []rune, args []string, remain string, err error) (bool, []string) { + dummyArg := "" + + // Empty command line, complete the root command. + if len(args) == 0 { + return true, append(args, dummyArg) + } + + // If we have an error, we must handle it later. + if err != nil { + return false, args + } + + // If the cursor is currentl on a space (as it is in most cases at the end + // of the line), we add our dummy argument for the completer to propose next. + if remain == "" && len(line) > 0 && unicode.IsSpace(line[len(line)-1]) { + return true, append(args, dummyArg) + } + + // Else there is a character under the cursor, which means we are + // in the middle/at the end of a posentially completed word. + return true, args +} + +func adjustQuotedPrefix(remain string, err error) (comp, line string) { + if errors.Is(err, errUnterminatedDoubleQuote) { + comp = "\"" + } else if errors.Is(err, errUnterminatedSingleQuote) { + comp = "'" + } + + line = comp + remain + + return +} + +// sanitizeArg unescapes a restrained set of characters. +func sanitizeArgs(args []string) (sanitized []string) { + replacer := strings.NewReplacer( + "\n", ` `, + "\t", ` `, + "\\ ", " ", // User-escaped spaces in words. + ) + + for _, arg := range args { + arg = replacer.Replace(arg) + sanitized = append(sanitized, arg) + } + + return sanitized +} + // split has been copied from go-shellquote and slightly modified so as to also // return the remainder when the parsing failed because of an unterminated quote. func splitCompWords(input string) (words []string, remainder string, err error) { @@ -208,8 +240,7 @@ func splitCompWords(input string) (words []string, remainder string, err error) word, input, err = splitCompWord(input, &buf) if err != nil { - remainder = input - return + return words, word + input, err } words = append(words, word) From fc705d970972576778e906eb3cec050daa82d382 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Tue, 15 Aug 2023 08:16:46 +0200 Subject: [PATCH 3/8] Other fixes to quotes/prefix escapes --- tab-completer.go | 80 ++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/tab-completer.go b/tab-completer.go index f7252db..776c378 100644 --- a/tab-completer.go +++ b/tab-completer.go @@ -34,14 +34,13 @@ func (c *Console) complete(line []rune, pos int) readline.Completions { raw := make([]readline.Completion, len(values)) for idx, val := range values { - value := readline.Completion{ - Value: val.Value, + raw[idx] = readline.Completion{ + Value: unescapeValue(prefixComp, prefixLine, val.Value), Display: val.Display, Description: val.Description, Style: val.Style, Tag: val.Tag, } - raw[idx] = value } // Assign both completions and command/flags/args usage strings. @@ -141,66 +140,76 @@ func splitArgs(line []rune, pos int) (args []string, prefixComp, prefixLine stri // in line is a space). // In some of those cases we append a single dummy argument // for the completer to understand we want a new word comp. - mustComplete, args := mustComplete(line, args, remain, err) + mustComplete, args, remain := mustComplete(line, args, remain, err) if mustComplete { - return sanitizeArgs(args), remain, remain + return sanitizeArgs(args), "", remain } - // The remainder is everything following the open charater. - // Pass it as is to the carapace completion engine. - args = append(args, remain) - // But the completion candidates themselves might need slightly // different prefixes, for an optimal completion experience. - prefixComp, prefixLine = adjustQuotedPrefix(remain, err) + arg, prefixComp, prefixLine := adjustQuotedPrefix(remain, err) + + // The remainder is everything following the open charater. + // Pass it as is to the carapace completion engine. + args = append(args, arg) return sanitizeArgs(args), prefixComp, prefixLine } -func mustComplete(line []rune, args []string, remain string, err error) (bool, []string) { +func mustComplete(line []rune, args []string, remain string, err error) (bool, []string, string) { dummyArg := "" // Empty command line, complete the root command. - if len(args) == 0 { - return true, append(args, dummyArg) + if len(args) == 0 || len(line) == 0 { + return true, append(args, dummyArg), remain } // If we have an error, we must handle it later. if err != nil { - return false, args + return false, args, remain } - // If the cursor is currentl on a space (as it is in most cases at the end - // of the line), we add our dummy argument for the completer to propose next. - if remain == "" && len(line) > 0 && unicode.IsSpace(line[len(line)-1]) { - return true, append(args, dummyArg) + lastChar := line[len(line)-1] + + // No remain and a trailing space means we want to complete + // for the next word, except when this last space was escaped. + if remain == "" && unicode.IsSpace(lastChar) { + if strings.HasSuffix(string(line), "\\ ") { + return true, args, args[len(args)-1] + } + + return true, append(args, dummyArg), remain } // Else there is a character under the cursor, which means we are // in the middle/at the end of a posentially completed word. - return true, args + return true, args, remain } -func adjustQuotedPrefix(remain string, err error) (comp, line string) { +func adjustQuotedPrefix(remain string, err error) (arg, comp, line string) { + arg = remain + if errors.Is(err, errUnterminatedDoubleQuote) { comp = "\"" + line = comp + arg } else if errors.Is(err, errUnterminatedSingleQuote) { comp = "'" + line = comp + arg + } else if errors.Is(err, errUnterminatedEscape) { + arg = strings.ReplaceAll(arg, "\\", "") } - line = comp + remain - - return + return arg, comp, line } +var replacer = strings.NewReplacer( + "\n", ` `, + "\t", ` `, + "\\ ", " ", // User-escaped spaces in words. +) + // sanitizeArg unescapes a restrained set of characters. func sanitizeArgs(args []string) (sanitized []string) { - replacer := strings.NewReplacer( - "\n", ` `, - "\t", ` `, - "\\ ", " ", // User-escaped spaces in words. - ) - for _, arg := range args { arg = replacer.Replace(arg) sanitized = append(sanitized, arg) @@ -209,6 +218,19 @@ func sanitizeArgs(args []string) (sanitized []string) { return sanitized } +// when the completer has returned us some completions, we sometimes +// needed to post-process them a little before passing them to our shell. +func unescapeValue(prefixComp, prefixLine, val string) string { + quoted := strings.HasPrefix(prefixLine, "\"") || + strings.HasPrefix(prefixLine, "'") + + if quoted { + val = strings.ReplaceAll(val, "\\ ", " ") + } + + return val +} + // split has been copied from go-shellquote and slightly modified so as to also // return the remainder when the parsing failed because of an unterminated quote. func splitCompWords(input string) (words []string, remainder string, err error) { From 4f91c8b2e0717053ef02ae1600a61036cd50325a Mon Sep 17 00:00:00 2001 From: maxlandon Date: Tue, 15 Aug 2023 08:47:47 +0200 Subject: [PATCH 4/8] Enhance keymap binds completion support. --- commands/readline/completers.go | 24 ++++++++++++++++++------ tab-completer.go => completer.go | 7 ++++--- syntax-highlighter.go => highlighter.go | 0 3 files changed, 22 insertions(+), 9 deletions(-) rename tab-completer.go => completer.go (98%) rename syntax-highlighter.go => highlighter.go (100%) diff --git a/commands/readline/completers.go b/commands/readline/completers.go index 121ab72..c0ab43a 100644 --- a/commands/readline/completers.go +++ b/commands/readline/completers.go @@ -20,6 +20,7 @@ package readline import ( "fmt" + "strings" "github.com/reeflective/readline" "github.com/reeflective/readline/inputrc" @@ -59,22 +60,33 @@ func completeBindSequences(sh *readline.Shell, cmd *cobra.Command) carapace.Acti } // Make a list of all sequences bound to each command, with descriptions. - cmdBinds := make([]string, 0) - insertBinds := make([]string, 0) + var cmdBinds, insertBinds []string for key, bind := range binds { + val := inputrc.Escape(key) + if bind.Action == "self-insert" { - insertBinds = append(insertBinds, "\""+inputrc.Escape(key)+"\"") + insertBinds = append(insertBinds, val) } else { - cmdBinds = append(cmdBinds, "\""+inputrc.Escape(key)+"\"") + cmdBinds = append(cmdBinds, val) cmdBinds = append(cmdBinds, bind.Action) } } - return carapace.Batch( + completions := carapace.Batch( carapace.ActionValues(insertBinds...).Tag(fmt.Sprintf("self-insert binds (%s)", keymap)).Usage("sequence"), carapace.ActionValuesDescribed(cmdBinds...).Tag(fmt.Sprintf("non-insert binds (%s)", keymap)).Usage("sequence"), - ).ToA() + ).ToA().Suffix("\"") + + // We're lucky and be particularly cautious about completion here: + // Look for the current argument and check whether or not it's quoted. + // If yes, only include quotes at the end of the inserted value. + // If no quotes, include them in both. + if strings.HasPrefix(ctx.Value, "\"") { + completions = completions.Prefix("\"") + } + + return completions }) } diff --git a/tab-completer.go b/completer.go similarity index 98% rename from tab-completer.go rename to completer.go index 776c378..783528b 100644 --- a/tab-completer.go +++ b/completer.go @@ -189,13 +189,14 @@ func mustComplete(line []rune, args []string, remain string, err error) (bool, [ func adjustQuotedPrefix(remain string, err error) (arg, comp, line string) { arg = remain - if errors.Is(err, errUnterminatedDoubleQuote) { + switch { + case errors.Is(err, errUnterminatedDoubleQuote): comp = "\"" line = comp + arg - } else if errors.Is(err, errUnterminatedSingleQuote) { + case errors.Is(err, errUnterminatedSingleQuote): comp = "'" line = comp + arg - } else if errors.Is(err, errUnterminatedEscape) { + case errors.Is(err, errUnterminatedEscape): arg = strings.ReplaceAll(arg, "\\", "") } diff --git a/syntax-highlighter.go b/highlighter.go similarity index 100% rename from syntax-highlighter.go rename to highlighter.go From 33d6356bbfb3fa78a5b8c4d8292e30dc23609d00 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Tue, 15 Aug 2023 09:01:47 +0200 Subject: [PATCH 5/8] Enhanced support for quoted readline bind completions --- commands/readline/completers.go | 3 ++- completer.go | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/commands/readline/completers.go b/commands/readline/completers.go index c0ab43a..c384db2 100644 --- a/commands/readline/completers.go +++ b/commands/readline/completers.go @@ -73,6 +73,7 @@ func completeBindSequences(sh *readline.Shell, cmd *cobra.Command) carapace.Acti } } + // Build the list of bind sequences bompletions completions := carapace.Batch( carapace.ActionValues(insertBinds...).Tag(fmt.Sprintf("self-insert binds (%s)", keymap)).Usage("sequence"), carapace.ActionValuesDescribed(cmdBinds...).Tag(fmt.Sprintf("non-insert binds (%s)", keymap)).Usage("sequence"), @@ -82,7 +83,7 @@ func completeBindSequences(sh *readline.Shell, cmd *cobra.Command) carapace.Acti // Look for the current argument and check whether or not it's quoted. // If yes, only include quotes at the end of the inserted value. // If no quotes, include them in both. - if strings.HasPrefix(ctx.Value, "\"") { + if strings.HasPrefix(ctx.Value, "\"") || ctx.Value == "" { completions = completions.Prefix("\"") } diff --git a/completer.go b/completer.go index 783528b..374c6ea 100644 --- a/completer.go +++ b/completer.go @@ -203,12 +203,6 @@ func adjustQuotedPrefix(remain string, err error) (arg, comp, line string) { return arg, comp, line } -var replacer = strings.NewReplacer( - "\n", ` `, - "\t", ` `, - "\\ ", " ", // User-escaped spaces in words. -) - // sanitizeArg unescapes a restrained set of characters. func sanitizeArgs(args []string) (sanitized []string) { for _, arg := range args { @@ -376,3 +370,9 @@ var re = regexp.MustCompile(ansi) func strip(str string) string { return re.ReplaceAllString(str, "") } + +var replacer = strings.NewReplacer( + "\n", ` `, + "\t", ` `, + "\\ ", " ", // User-escaped spaces in words. +) From 78bec00215885c97d60543eea0566683be7f8e13 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Wed, 16 Aug 2023 11:17:41 +0200 Subject: [PATCH 6/8] Better naming and comments for new exported functions --- menu.go | 16 ++++++++------- run.go | 63 +++++++++++++++++---------------------------------------- 2 files changed, 27 insertions(+), 52 deletions(-) diff --git a/menu.go b/menu.go index c3564e9..2159719 100644 --- a/menu.go +++ b/menu.go @@ -192,15 +192,17 @@ func (m *Menu) Printf(msg string, args ...any) (n int, err error) { return m.console.Printf(buf) } -// ErrUnavailableCommand checks if a target command is marked as filtered as per the console -// application registered/and or active filters (added with console.Hide/ShowCommand()), and -// if yes, returns a template-formatted error message showing the list of incompatible filters. -func (m *Menu) ErrUnavailableCommand(target *cobra.Command) error { - if target == nil { +// CheckIsAvailable checks if a target command is marked as filtered +// by the console application registered/and or active filters (added +// with console.Hide/ShowCommand()). +// If filtered, returns a template-formatted error message showing the +// list of incompatible filters. If not filtered, no error is returned. +func (m *Menu) CheckIsAvailable(cmd *cobra.Command) error { + if cmd == nil { return nil } - filters := m.ActiveFiltersFor(target) + filters := m.ActiveFiltersFor(cmd) if len(filters) == 0 { return nil } @@ -209,7 +211,7 @@ func (m *Menu) ErrUnavailableCommand(target *cobra.Command) error { err := tmpl(&bufErr, m.errorFilteredCommandTemplate(filters), map[string]interface{}{ "menu": m, - "cmd": target, + "cmd": cmd, "filters": filters, }) diff --git a/run.go b/run.go index 26bd40a..b14a7df 100644 --- a/run.go +++ b/run.go @@ -89,47 +89,25 @@ func (c *Console) Start() error { } } -// ExecuteOnce is a wrapper around the classic one-time cobra command execution. -// This call is thus blocking during the entire parsing and execution process -// of a command-line. -// -// This function should be useful if you have trees of commands that can -// be executed both in closed-loop applications or in a one-off exec style. -// Normally, most commands should, if your command behavior/API has no magic. -// -// The command line (os.Args) is matched against the currently active menu. -// Be sure to set and verify this menu before calling this function. -// This function also does not print any application logo. -func (c *Console) ExecuteOnce() error { - // Always ensure we work with the active menu, with freshly - // generated commands, bound prompts and some other things. - menu := c.activeMenu() - menu.resetPreRun() - - c.printed = false - - if c.NewlineBefore { - fmt.Println() - } - - // Run user-provided pre-run line hooks, - // which may modify the input line args. - args, err := c.runLineHooks(os.Args) - if err != nil { - return fmt.Errorf("line error: %s", err.Error()) - } +// RunCommandArgs is a convenience function to run a command line in a given menu. +// After running, the menu's commands are reset, and the prompts reloaded, therefore +// mostly mimicking the behavior that is the one of the normal readline/run/readline +// workflow. +// Although state segregation is a priority for this library to be ensured as much +// as possible, you should be cautious when using this function to run commands. +func (m *Menu) RunCommandArgs(args []string) (err error) { + // The menu used and reset is the active menu. + // Prepare its output buffer for the command. + m.resetPreRun() - // Run all pre-run hooks and the command itself - // Don't check the error: if its a cobra error, - // the library user is responsible for setting - // the cobra behavior. - // If it's an interrupt, we take care of it. - return c.execute(menu, args, false) + // Run the command and associated helpers. + return m.console.execute(m, args, !m.console.isExecuting) } -// RunCommand is a convenience function to run a command in a given menu. -// After running, the menu commands are reset, and the prompts reloaded. -func (m *Menu) RunCommand(line string) (err error) { +// RunCommandLine is the equivalent of menu.RunCommandArgs(), but accepts +// an unsplit command line to execute. This line is split and processed in +// *sh-compliant form, identically to how lines are in normal console usage. +func (m *Menu) RunCommandLine(line string) (err error) { if len(line) == 0 { return } @@ -140,12 +118,7 @@ func (m *Menu) RunCommand(line string) (err error) { return fmt.Errorf("line error: %w", err) } - // The menu used and reset is the active menu. - // Prepare its output buffer for the command. - m.resetPreRun() - - // Run the command and associated helpers. - return m.console.execute(m, args, !m.console.isExecuting) + return m.RunCommandArgs(args) } // execute - The user has entered a command input line, the arguments have been processed: @@ -173,7 +146,7 @@ func (c *Console) execute(menu *Menu, args []string, async bool) (err error) { // Find the target command: if this command is filtered, don't run it. target, _, _ := cmd.Find(args) - if err := menu.ErrUnavailableCommand(target); err != nil { + if err := menu.CheckIsAvailable(target); err != nil { return err } From d3f9258e47fc925ec127585a87f6db73c901c6c1 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Wed, 16 Aug 2023 11:42:54 +0200 Subject: [PATCH 7/8] Update readline and carapace dependencies --- go.mod | 12 +++++++----- go.sum | 10 ++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 88e95c8..f601f37 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,16 @@ module github.com/reeflective/console -go 1.20 +go 1.21 + +toolchain go1.21.0 require ( github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 - github.com/reeflective/readline v1.0.4 - github.com/rsteube/carapace v0.36.3 + github.com/reeflective/readline v1.0.9 + github.com/rsteube/carapace v0.43.0 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 + golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 ) require ( @@ -15,11 +18,10 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/rivo/uniseg v0.4.4 // indirect - golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 // indirect golang.org/x/sys v0.8.0 // indirect golang.org/x/term v0.8.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/rsteube/carapace v0.36.3 => github.com/reeflective/carapace v0.25.2-0.20230602202234-e8d757e458ca +replace github.com/rsteube/carapace v0.43.0 => github.com/reeflective/carapace v0.25.2-0.20230816093630-a30f5184fa0d diff --git a/go.sum b/go.sum index b348d55..adab06f 100644 --- a/go.sum +++ b/go.sum @@ -14,16 +14,14 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/reeflective/carapace v0.25.2-0.20230602202234-e8d757e458ca h1:tD797h1qmNtS/2z6Y7EtIg7OXEDaoSuULsUoksEepmQ= -github.com/reeflective/carapace v0.25.2-0.20230602202234-e8d757e458ca/go.mod h1:jkLt41Ne2TD2xPuMdX/2O05Smhy8vMgG7O2TYvC0yOc= -github.com/reeflective/readline v1.0.4 h1:0Uzdtm/K6SWs3Y2xYiCXjrhM8g0XdwvU6+c7t1r+ks8= -github.com/reeflective/readline v1.0.4/go.mod h1:5JgnHb/ZCvp/6RUA59HEansPBxWTkyBO4hJ5LL9Fp1Y= +github.com/reeflective/carapace v0.25.2-0.20230816093630-a30f5184fa0d h1:RK0OaQs+3CMJnfXc5SNEg+Kbu4A2AVljPuG5/HcaUdM= +github.com/reeflective/carapace v0.25.2-0.20230816093630-a30f5184fa0d/go.mod h1:jkLt41Ne2TD2xPuMdX/2O05Smhy8vMgG7O2TYvC0yOc= +github.com/reeflective/readline v1.0.9 h1:ZA+V4HIWonwn8B4gUaaKwPtBogch19qgdk1I+hqULdk= +github.com/reeflective/readline v1.0.9/go.mod h1:mcD0HxNVJVteVwDm9caXKg52nQACVyfh8EyuBmgVlzY= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rsteube/carapace v0.36.3 h1:GkdL9SF5sJH8pBasDWCX5nkD3nS0M0+e792A18FFfKQ= -github.com/rsteube/carapace v0.36.3/go.mod h1:jkLt41Ne2TD2xPuMdX/2O05Smhy8vMgG7O2TYvC0yOc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= From 6ec1ce41d07f1a6759bf82186cfa9d886dfc5cf7 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Wed, 16 Aug 2023 11:48:14 +0200 Subject: [PATCH 8/8] Fix go.mod toolchains --- .github/workflows/go.yml | 4 ++-- go.mod | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 73a1b7f..1521716 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: '1.20' + go-version: '1.21' - name: Build run: go build -v ./... @@ -42,7 +42,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: '1.20' + go-version: '1.21' - name: Build run: go build -v ./... diff --git a/go.mod b/go.mod index f601f37..d9de271 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/reeflective/console go 1.21 -toolchain go1.21.0 - require ( github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/reeflective/readline v1.0.9