From 2b54c6f58704919c5049fdc883a91e155593d1c7 Mon Sep 17 00:00:00 2001 From: sora233 Date: Sun, 10 Jan 2021 23:33:09 +0800 Subject: [PATCH] fix memory & extra log & prompt prefix --- cli/executor.go | 1 - cli/grammar.go | 3 +++ main.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/executor.go b/cli/executor.go index c97f310..2234de0 100644 --- a/cli/executor.go +++ b/cli/executor.go @@ -41,7 +41,6 @@ func BuntdbExecutor(s string) { } tx, rw := db.GetCurrentTransaction() if ctx.Selected().Name == "use" { - fmt.Printf("tx %v", tx) err = ctx.Run(tx) if err != nil { fmt.Printf("ERR: %v\n", err) diff --git a/cli/grammar.go b/cli/grammar.go index 66e1e07..029c69f 100644 --- a/cli/grammar.go +++ b/cli/grammar.go @@ -112,6 +112,9 @@ func (u *UseGrammar) Run(ctx *kong.Context, tx *buntdb.Tx) error { if tx != nil { return db.ErrTransactionExist } + if u.Path == ":memory:" { + return db.InitBuntDB(u.Path) + } f, err := os.Lstat(u.Path) if err != nil { if !os.IsNotExist(err) { diff --git a/main.go b/main.go index b2ea7b4..c1efe6f 100644 --- a/main.go +++ b/main.go @@ -38,9 +38,9 @@ func main() { prompt.OptionLivePrefix(func() (prefix string, useLivePrefix bool) { tx, rw := db.GetCurrentTransaction() if tx != nil { - return path.Base(CLI.Path) + fmt.Sprintf("(%v)", db.RWDescribe(rw)) + "> ", true + return path.Base(db.GetDbPath()) + fmt.Sprintf("(%v)", db.RWDescribe(rw)) + "> ", true } else { - return path.Base(CLI.Path) + "> ", true + return path.Base(db.GetDbPath()) + "> ", true } }), prompt.OptionSetExitCheckerOnInput(func(in string, breakline bool) bool {