Skip to content

Commit

Permalink
cmd/viewcore: migrate from chzyer/readline to ergochat/readline
Browse files Browse the repository at this point in the history
Replaced the readline module from github.com/chzyer/readline to github.com/ergochat/readline.
Key changes involve updating the auto-completion functionality and modifying the method calls to handle
the differences in the new readline API.

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]>
  • Loading branch information
mikelolasagasti committed Sep 4, 2024
1 parent 93976b9 commit eb26bbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
12 changes: 6 additions & 6 deletions cmd/viewcore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.23.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
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.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=

0 comments on commit eb26bbb

Please sign in to comment.