Init
This commit is contained in:
1 parent
79e240037f
commit
9078060e65
20 files changed
+1152
No files matched your search
@@ -0,0 +1,54 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func Get() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get configuration info by module_name",
|
||||
Action: get.action,
|
||||
}
|
||||
}
|
||||
|
||||
var get getCommand
|
||||
|
||||
type getCommand struct{}
|
||||
|
||||
func (g getCommand) action(c *cli.Context) {
|
||||
if err := checkFlags(c); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
moduleName := c.Args().First()
|
||||
pathObject := c.Args().Get(1)
|
||||
|
||||
moduleConfiguration, jsonObject := getModuleConfiguration(moduleName)
|
||||
if moduleConfiguration == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
printAnswer(moduleConfiguration.Data)
|
||||
} else {
|
||||
g.checkObject(jsonObject, pathObject)
|
||||
}
|
||||
}
|
||||
|
||||
func (g getCommand) checkObject(jsonObject []byte, depth string) {
|
||||
jsonString := gjson.Get(string(jsonObject), depth)
|
||||
if jsonString.Raw == "" {
|
||||
fmt.Printf("Path '%s' not found\n", depth)
|
||||
} else {
|
||||
var data interface{}
|
||||
if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
printAnswer(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user