-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
74 lines (69 loc) · 1.37 KB
/
run.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
package main
import (
"github.com/urfave/cli"
pscfLog "github.com/liupeidong0620/pscf/log"
)
func run(c *cli.Context, mod string, args []string) error {
var commandErr error
var verbose bool
if c.IsSet("v") {
verbose = true
} else {
verbose = false
}
// parse command line param
pscfLog.LogInit(mod, verbose)
command, err := isParamSet(c, args)
if err != nil {
return err
}
route, value, err := parseParamNode(c, command, mod)
if err != nil {
return err
}
// module init
module, err := modules_init(mod, c.String(CommandFile))
if err != nil {
return err
}
// ignore some field
if c.IsSet(CommandIgnore) && mod == YAMLTOOL {
ignoreData := yamlAttribute{
ignoreField: c.String(CommandIgnore),
}
err := set_module_attribute(mod, ignoreData)
if err != nil {
return err
}
}
// load yaml comment
if c.IsSet(CommandComment) &&
mod == YAMLTOOL && command != CommandGetKeys {
setYamlCommentEnable(true)
}
// add del set mod get operation
switch command {
case CommandDel:
commandErr = module.Del(route)
case CommandSet:
commandErr = module.Set(route, value)
case CommandGet:
_, err := module.Get(route)
if err != nil {
return err
}
return nil
case CommandGetKeys:
_, err := module.GetKeys(route)
if err != nil {
}
return nil
default:
// error
}
if commandErr != nil {
return commandErr
}
module.Save()
return nil
}