From cac3e03ffcbc8dd60e1feed147568fb444daabb1 Mon Sep 17 00:00:00 2001 From: Mikel Olasagasti Uranga Date: Wed, 4 Sep 2024 12:52:29 +0200 Subject: [PATCH] cmd/viewcore: migrate from chzyer/readline to ergochat/readline Module ergochat/readline is a fork that is actively maintained and includes numerous bug fixes that are not present in the original module. Additionally, this change reduces the number of indirect dependencies by removing the need for github.com/chzyer/logex and github.com/chzyer/test. Details: - Updated imports and removed old module dependencies. - Replaced Terminal field references with Stdout method calls for shell output. - Modified the cmdToCompleter function to adapt to the new PrefixCompleter structure. - Ensured the completion tree is built using the new SetChildren and Children methods. Signed-off-by: Mikel Olasagasti Uranga --- cmd/viewcore/main.go | 12 ++++++------ go.mod | 5 ++--- go.sum | 10 ++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/cmd/viewcore/main.go b/cmd/viewcore/main.go index 9f0d999..c11a293 100644 --- a/cmd/viewcore/main.go +++ b/cmd/viewcore/main.go @@ -24,7 +24,7 @@ import ( "sync" "text/tabwriter" - "github.com/chzyer/readline" + "github.com/ergochat/readline" "github.com/spf13/cobra" "github.com/spf13/pflag" "golang.org/x/debug/internal/core" @@ -340,11 +340,11 @@ func runRoot(cmd *cobra.Command, args []string) { defer shell.Close() // nice welcome message. - fmt.Fprintln(shell.Terminal) + fmt.Fprintln(shell.Stdout()) if args := p.Args(); args != "" { - fmt.Fprintf(shell.Terminal, "Core %q was generated by %q\n", cfg.corefile, args) + fmt.Fprintf(shell.Stdout(), "Core %q was generated by %q\n", cfg.corefile, args) } - fmt.Fprintf(shell.Terminal, "Entering interactive mode (type 'help' for commands)\n") + fmt.Fprintf(shell.Stdout(), "Entering interactive mode (type 'help' for commands)\n") for { l, err := shell.Readline() @@ -377,9 +377,9 @@ func capturePanic(fn func()) (err error) { return nil } -func cmdToCompleter(parent readline.PrefixCompleterInterface, c *cobra.Command) { +func cmdToCompleter(parent *readline.PrefixCompleter, c *cobra.Command) { completer := readline.PcItem(c.Name()) - parent.SetChildren(append(parent.GetChildren(), completer)) + parent.SetChildren(append(parent.Children, completer)) for _, child := range c.Commands() { cmdToCompleter(completer, child) } diff --git a/go.mod b/go.mod index 1c79a25..08678b7 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,13 @@ module golang.org/x/debug go 1.18 require ( - github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e + github.com/ergochat/readline v0.1.2 github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.3 golang.org/x/sys v0.25.0 ) require ( - github.com/chzyer/logex v1.1.10 // indirect - github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect + golang.org/x/text v0.9.0 // indirect ) diff --git a/go.sum b/go.sum index c144b98..71eb767 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,5 @@ -github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/ergochat/readline v0.1.2 h1:zxiwQB8DyTLD0HSWthJlnvs5E2X1qnyXZ44RFf1jRlg= +github.com/ergochat/readline v0.1.2/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= @@ -12,3 +8,5 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=