mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 21:40:22 +08:00
Add initial main func
This commit is contained in:
56
main.go
Normal file
56
main.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Dparker1990/dbg/command"
|
||||||
|
)
|
||||||
|
|
||||||
|
type term struct {
|
||||||
|
stdin *bufio.Reader
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var (
|
||||||
|
t = newTerm()
|
||||||
|
cmds = command.DebugCommands()
|
||||||
|
)
|
||||||
|
|
||||||
|
for {
|
||||||
|
cmdstr, err := t.promptForInput()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprint(os.Stderr, "Prompt for input failed.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := cmds.Find(cmdstr)
|
||||||
|
err = cmd()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Command failed: %s\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTerm() *term {
|
||||||
|
return &term{
|
||||||
|
stdin: bufio.NewReader(os.Stdin),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *term) promptForInput() (string, error) {
|
||||||
|
fmt.Print("dbg> ")
|
||||||
|
|
||||||
|
line, err := t.stdin.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return stripNewLine(line), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func stripNewLine(s string) string {
|
||||||
|
return strings.TrimSuffix(s, "\n")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user