add(readme)

This commit is contained in:
DeniskaRediska committed 2019-07-17 14:01:02 +03:00
1 parent 9078060e65
commit a54239f971
9 files changed
+343 -7

No files matched your search

+20
View File
@@ -57,6 +57,26 @@ func checkFlags(c *cli.Context) error {
return nil
}
func checkPath(pathObject string) (string, bool) {
str := strings.Split(pathObject, ".")
pathObject = ""
if len(str) == 1 || str[0] != "" {
fmt.Println("Path must start with '.'")
return pathObject, false
}
for key, value := range str {
if key == 0 {
continue
}
if key == 1 {
pathObject = fmt.Sprintf("%s", value)
continue
}
pathObject = fmt.Sprintf("%s.%s", pathObject, value)
}
return pathObject, true
}
func printAnswer(data interface{}) {
if answer, err := json.MarshalIndent(data, "", " "); err != nil {
fmt.Println(err)
+6 -1
View File
@@ -9,7 +9,7 @@ import (
func Delete() cli.Command {
return cli.Command{
Name: "delete",
Usage: "delete configuration info by module_name",
Usage: "delete configuration by module_name",
Action: deleteComm.action,
}
}
@@ -31,6 +31,11 @@ func (d deleteCommand) action(c *cli.Context) {
return
}
pathObject, ok := checkPath(pathObject)
if !ok {
return
}
if pathObject == "" {
createUpdateConfig("", moduleConfiguration)
} else {
+6 -1
View File
@@ -10,7 +10,7 @@ import (
func Get() cli.Command {
return cli.Command{
Name: "get",
Usage: "get configuration info by module_name",
Usage: "get configuration by module_name",
Action: get.action,
}
}
@@ -32,6 +32,11 @@ func (g getCommand) action(c *cli.Context) {
return
}
pathObject, ok := checkPath(pathObject)
if !ok {
return
}
if pathObject == "" {
printAnswer(moduleConfiguration.Data)
} else {
+6 -1
View File
@@ -13,7 +13,7 @@ import (
func Set() cli.Command {
return cli.Command{
Name: "set",
Usage: "set configuration info",
Usage: "set configuration by module_name",
Action: set.action,
}
}
@@ -37,6 +37,11 @@ func (s setCommand) action(c *cli.Context) {
return
}
pathObject, ok := checkPath(pathObject)
if !ok {
return
}
if changeObject == "" {
fmt.Print("Enter new value: ")
scanner := bufio.NewScanner(os.Stdin)