forked from micro/micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
62 lines (51 loc) · 966 Bytes
/
commands.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
package config
import (
"fmt"
"github.com/urfave/cli/v2"
)
var (
// Commands defines a set of commands for local config
Commands = []*cli.Command{
{
Name: "get",
Usage: "Get a value by specifying [key] as an arg",
Action: get,
},
{
Name: "set",
Usage: "Set a key-val using [key] [value] as args",
Action: set,
},
{
Name: "delete",
Usage: "Delete a value using [key] as an arg",
Action: del,
},
}
)
func get(ctx *cli.Context) error {
args := ctx.Args()
key := args.Get(0)
val := args.Get(1)
val, err := Get(key)
if err != nil {
return err
}
fmt.Println(val)
return nil
}
func set(ctx *cli.Context) error {
args := ctx.Args()
key := args.Get(0)
val := args.Get(1)
return Set(key, val)
}
func del(ctx *cli.Context) error {
args := ctx.Args()
key := args.Get(0)
if len(key) == 0 {
return fmt.Errorf("key cannot be blank")
}
// TODO: actually delete the key also
return Set(key, "")
}