Skip to content

Commit

Permalink
show err when db invalid & update exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora233 committed Jan 16, 2021
1 parent e1d28ee commit 2433758
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/c-bata/go-prompt"
"os"
"path"
"strings"
)

var CLI struct {
Expand All @@ -18,7 +19,6 @@ var CLI struct {

func main() {
kong.Parse(&CLI, kong.UsageOnError(), kong.Name("buntdb-cli"))
defer os.Exit(0)

if CLI.Debug {
cli.Debug = true
Expand All @@ -28,7 +28,11 @@ func main() {
CLI.Path = db.GetTempDbPath("buntdb-cli")
}

db.InitBuntDB(CLI.Path)
err := db.InitBuntDB(CLI.Path)
if err != nil {
fmt.Printf("ERR: %v\n", err)
os.Exit(1)
}
defer db.Close()

p := prompt.New(
Expand All @@ -44,7 +48,7 @@ func main() {
}
}),
prompt.OptionSetExitCheckerOnInput(func(in string, breakline bool) bool {
return in == "exit" && breakline
return strings.TrimSpace(in) == "exit" && breakline
}),
)
p.Run()
Expand Down

0 comments on commit 2433758

Please sign in to comment.