From 97f88562c4d292fdf561f8838f4605c575be67c8 Mon Sep 17 00:00:00 2001 From: Kay Date: Tue, 9 Jul 2024 18:23:26 +0000 Subject: [PATCH] fix: add todos --- .golangci.yml | 1 - cmd/commands/repl.go | 61 ++++++++++++++--------------------------- cmd/commands/ttrace.txt | 3 +- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2156cfa..828bd5f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,7 +7,6 @@ linters: - staticcheck - unused - gocognit - - godox - godot - gocritic - wsl diff --git a/cmd/commands/repl.go b/cmd/commands/repl.go index 63bff28..a7676a5 100644 --- a/cmd/commands/repl.go +++ b/cmd/commands/repl.go @@ -6,9 +6,7 @@ import ( "net" "os" "os/exec" - "path/filepath" "runtime" - "strings" "time" "github.com/peterh/liner" @@ -16,19 +14,11 @@ import ( "github.com/zurvan-lab/TimeTrace/utils/errors" ) -var ( - //go:embed ttrace.txt - welcomeASCII []byte - - history = filepath.Join(os.TempDir(), ".time_trace_repl_history") - - TQL_COMMANDS = [...]string{ - "CON", "PING", "SET", "SSET", "PUSH", "GET", "CNTS", - "CNTSS", "CNTE", "CLN", "CLNS", "CLNSS", "DRPS", "DRPSS", "SS", - } - - clear map[string]func() -) +/* + TODO: Add history support for me. + TODO: Add suggestion for me. + TODO: Add completer for me. +*/ func init() { clear = make(map[string]func()) @@ -44,6 +34,18 @@ func init() { } } +var ( + //go:embed ttrace.txt + welcomeASCII []byte + + TQL_COMMANDS = [...]string{ + "CON", "PING", "SET", "SSET", "PUSH", "GET", "CNTS", + "CNTSS", "CNTE", "CLN", "CLNS", "CLNSS", "DRPS", "DRPSS", "SS", + } + + clear map[string]func() +) + const ( PROMPT = ">> " ) @@ -70,12 +72,6 @@ func ConnectCommand(parentCmd *cobra.Command) { defer lnr.Close() lnr.SetCtrlCAborts(true) - lnr.SetCompleter(completer) - - if f, err := os.Open(history); err == nil { - _, _ = lnr.ReadHistory(f) - f.Close() - } conQuery := fmt.Sprintf("CON %v %v", *username, *password) response := do(conn, conQuery) @@ -90,6 +86,10 @@ func ConnectCommand(parentCmd *cobra.Command) { os.Exit(0) } + if input == "clean" { + cleanTerminal() + } + lnr.AppendHistory(input) cmd.Print(fmt.Sprintf("%s\n", do(conn, input))) } @@ -97,13 +97,6 @@ func ConnectCommand(parentCmd *cobra.Command) { } else { ExitOnError(cmd, fmt.Errorf("%w: %s", errors.ErrInvalidCommand, response)) } - - if f, err := os.Create(history); err != nil { - cmd.Printf("Error writing history file: %s\n", err) - } else { - _, _ = lnr.WriteHistory(f) - f.Close() - } } } @@ -130,18 +123,6 @@ func do(conn net.Conn, q string) string { return string(resBuf[:n]) } -func completer(line string) []string { - r := make([]string, 15) - - for _, c := range TQL_COMMANDS { - if strings.Contains(c, line) { - r = append(r, c) - } - } - - return r -} - func cleanTerminal() { cf, ok := clear[runtime.GOOS] if ok { diff --git a/cmd/commands/ttrace.txt b/cmd/commands/ttrace.txt index 608ed9e..e94b14d 100644 --- a/cmd/commands/ttrace.txt +++ b/cmd/commands/ttrace.txt @@ -7,4 +7,5 @@ Welcome to time-trace REPL! You can execute TQL command and apply changes to connected instance here. see: https://github.com/zurvan-lab/TimeTrace/blob/main/doc/TQL/TQL.md -use exit to exit the repl gracefully. +You can clean the screen using clean command. +Use exit to exit the REPL gracefully.