Skip to content

Commit 46be18b

Browse files
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 <[email protected]>
1 parent 93976b9 commit 46be18b

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

cmd/viewcore/main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"sync"
2525
"text/tabwriter"
2626

27-
"github.com/chzyer/readline"
27+
"github.com/ergochat/readline"
2828
"github.com/spf13/cobra"
2929
"github.com/spf13/pflag"
3030
"golang.org/x/debug/internal/core"
@@ -340,11 +340,11 @@ func runRoot(cmd *cobra.Command, args []string) {
340340
defer shell.Close()
341341

342342
// nice welcome message.
343-
fmt.Fprintln(shell.Terminal)
343+
fmt.Fprintln(shell.Stdout())
344344
if args := p.Args(); args != "" {
345-
fmt.Fprintf(shell.Terminal, "Core %q was generated by %q\n", cfg.corefile, args)
345+
fmt.Fprintf(shell.Stdout(), "Core %q was generated by %q\n", cfg.corefile, args)
346346
}
347-
fmt.Fprintf(shell.Terminal, "Entering interactive mode (type 'help' for commands)\n")
347+
fmt.Fprintf(shell.Stdout(), "Entering interactive mode (type 'help' for commands)\n")
348348

349349
for {
350350
l, err := shell.Readline()
@@ -377,9 +377,9 @@ func capturePanic(fn func()) (err error) {
377377
return nil
378378
}
379379

380-
func cmdToCompleter(parent readline.PrefixCompleterInterface, c *cobra.Command) {
380+
func cmdToCompleter(parent *readline.PrefixCompleter, c *cobra.Command) {
381381
completer := readline.PcItem(c.Name())
382-
parent.SetChildren(append(parent.GetChildren(), completer))
382+
parent.SetChildren(append(parent.Children, completer))
383383
for _, child := range c.Commands() {
384384
cmdToCompleter(completer, child)
385385
}

go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ module golang.org/x/debug
33
go 1.18
44

55
require (
6-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
6+
github.com/ergochat/readline v0.1.2
77
github.com/spf13/cobra v0.0.3
88
github.com/spf13/pflag v1.0.3
99
golang.org/x/sys v0.23.0
1010
)
1111

1212
require (
13-
github.com/chzyer/logex v1.1.10 // indirect
14-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect
1513
github.com/inconshreveable/mousetrap v1.0.0 // indirect
14+
golang.org/x/text v0.9.0 // indirect
1615
)

go.sum

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
2-
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
3-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
4-
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
6-
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
1+
github.com/ergochat/readline v0.1.2 h1:zxiwQB8DyTLD0HSWthJlnvs5E2X1qnyXZ44RFf1jRlg=
2+
github.com/ergochat/readline v0.1.2/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY=
73
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
84
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
95
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
@@ -12,3 +8,5 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
128
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
139
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
1410
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11+
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
12+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=

0 commit comments

Comments
 (0)