-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
89 lines (83 loc) · 1.73 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "zed-prompts",
Usage: "Import and export prompts from LMDB database",
Commands: []*cli.Command{
{
Name: "export",
Usage: "Export prompts from LMDB to JSON",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "db",
Aliases: []string{"d"},
Value: dbPath(),
Usage: "LMDB database path",
Required: false,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "Output JSON file (use '-' for stdout)",
Required: true,
},
},
Action: func(c *cli.Context) error {
return runExport(c.String("db"), c.String("output"))
},
},
{
Name: "import",
Usage: "Import prompts from JSON to LMDB",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "input",
Aliases: []string{"i"},
Usage: "Input JSON file (use '-' for stdin)",
Required: true,
},
&cli.StringFlag{
Name: "db",
Aliases: []string{"d"},
Value: dbPath(),
Usage: "LMDB database path",
Required: false,
},
},
Action: func(c *cli.Context) error {
return runImport(c.String("input"), c.String("db"))
},
},
{
Name: "list",
Usage: "List prompts",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
return listMetadata()
},
},
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Printf("error: %+v\n", err)
}
}
func runExport(dbPath string, output string) error {
return export(
dbPath,
output,
)
}
func runImport(input string, dbPath string) error {
os.MkdirAll(dbPath, 0755)
return importJSON(
input,
dbPath,
)
}