-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcli.go
More file actions
64 lines (58 loc) · 1.18 KB
/
cli.go
File metadata and controls
64 lines (58 loc) · 1.18 KB
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
package main
import (
"bytes"
"io"
"io/ioutil"
"log"
"os"
"github.com/av-elier/nutsdb-cli/comm"
"github.com/av-elier/nutsdb-cli/db"
"github.com/urfave/cli"
)
type args struct {
db string
command string
}
func main() {
var args args
app := &cli.App{
Name: "nutsdb-cli",
Flags: []cli.Flag{
cli.StringFlag{
Name: "command",
Usage: "a command to execute instead of starting repl",
Destination: &args.command,
},
cli.StringFlag{
Name: "db",
Usage: "path to nutsdb database",
Destination: &args.db,
Required: true,
},
},
Commands: []cli.Command{
{
Name: "debug",
Usage: "Insert sample data into the specified database",
Action: func(c *cli.Context) error {
impl := db.NutsDB{DbDir: args.db}
impl.CreateDebugDb()
return nil
},
},
},
Action: func(c *cli.Context) error {
nuts := db.NutsDB{DbDir: args.db}
var in io.ReadCloser = os.Stdin
if args.command != "" {
in = ioutil.NopCloser(bytes.NewReader([]byte(args.command)))
}
comm := comm.NewCommunicator(in, nuts)
return comm.Run()
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}