-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (42 loc) · 971 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"os"
"github.com/mitchellh/go-homedir"
"github.com/rogaps/kp2cli/terminal"
"github.com/tobischo/gokeepasslib/v3"
)
var (
db *gokeepasslib.Database
cwd workingGroup
)
func setCwd(t *terminal.Term, c workingGroup) {
cwd = c
t.SetPrompt(fmt.Sprintf("%s:%s> ", "kp2cli", cwd.String()))
}
func setDb(t *terminal.Term, d *gokeepasslib.Database) {
db = d
setCwd(t, newRootGroup(db))
}
func main() {
var err error
var historyFilePath string
var exitCode int
t := terminal.NewTerm(&terminal.TermConfig{})
t.SetCommands(cmds...)
historyFilePath, err = homedir.Expand("~/.kp2cli_history")
if err != nil {
historyFilePath = ".kp2cli_history"
}
t.SetHistoryFile(historyFilePath)
setDb(t, newDatabase())
setCwd(t, newRootGroup(db))
fmt.Println("kp2cli, Keepass 2 Interactive Shell")
fmt.Println("Type \"help\" for help.")
fmt.Println()
t.Run()
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(exitCode)
}
}