fix json output
This commit is contained in:
1 parent
b65cda4099
commit
3eeb933231
28 files changed
+180
-595
No files matched your search
@@ -2,16 +2,15 @@ package common_config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Contain() cli.Command {
|
||||
return cli.Command{
|
||||
func Contain() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "contain",
|
||||
Usage: "availability common configuration in module",
|
||||
Action: contain.action,
|
||||
@@ -23,28 +22,25 @@ var contain containCommand
|
||||
|
||||
type containCommand struct{}
|
||||
|
||||
func (g containCommand) action(ctx *cli.Context) {
|
||||
func (g containCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
|
||||
if configName == "" {
|
||||
utils.PrintError(errors.New("empty common config name"))
|
||||
return
|
||||
return errors.New("empty common config name")
|
||||
}
|
||||
|
||||
config, err := service.Config.GetCommonConfigByName(configName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
links, err := service.Config.GetLinksCommonConfig(config.Id)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return err
|
||||
} else {
|
||||
fmt.Printf("config [%s] linked with next modules:\n", configName)
|
||||
for _, link := range links {
|
||||
@@ -52,4 +48,5 @@ func (g containCommand) action(ctx *cli.Context) {
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2,17 +2,17 @@ package common_config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Delete() cli.Command {
|
||||
return cli.Command{
|
||||
func Delete() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "set common configurations",
|
||||
Action: deleteComm.action,
|
||||
@@ -24,44 +24,39 @@ var deleteComm deleteCommand
|
||||
|
||||
type deleteCommand struct{}
|
||||
|
||||
func (g deleteCommand) action(ctx *cli.Context) {
|
||||
func (g deleteCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
if configName == "" {
|
||||
utils.PrintError(errors.New("empty config name"))
|
||||
return
|
||||
return errors.New("empty config name")
|
||||
}
|
||||
|
||||
pathObject, err := utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
config, err := service.Config.GetCommonConfigByName(configName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
utils.CreateUpdateCommonConfig("", config)
|
||||
return utils.CreateUpdateCommonConfig("", config)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(config.Data)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
|
||||
utils.PrintError(err)
|
||||
return err
|
||||
} else {
|
||||
utils.CreateUpdateCommonConfig(stringToChange, config)
|
||||
return utils.CreateUpdateCommonConfig(stringToChange, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,16 @@ package common_config
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Get() cli.Command {
|
||||
return cli.Command{
|
||||
func Get() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get common configurations",
|
||||
Action: get.action,
|
||||
@@ -24,10 +24,9 @@ var get getCommand
|
||||
|
||||
type getCommand struct{}
|
||||
|
||||
func (g getCommand) action(ctx *cli.Context) {
|
||||
func (g getCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
@@ -35,8 +34,7 @@ func (g getCommand) action(ctx *cli.Context) {
|
||||
|
||||
commonConfigs, err := service.Config.GetMapNameCommonConfig()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if configName == "" {
|
||||
@@ -45,26 +43,25 @@ func (g getCommand) action(ctx *cli.Context) {
|
||||
fmt.Printf("[%s] ", name)
|
||||
}
|
||||
fmt.Println()
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
pathObject, err = utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
config, ok := commonConfigs[configName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", configName))
|
||||
return
|
||||
return errors.Errorf("common config [%s] not found", configName)
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
utils.PrintAnswer(config.Data)
|
||||
} else if jsonObject, err := json.Marshal(config.Data); err != nil {
|
||||
utils.PrintError(err)
|
||||
return err
|
||||
} else {
|
||||
utils.CheckObject(jsonObject, pathObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Link() cli.Command {
|
||||
return cli.Command{
|
||||
func Link() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "link",
|
||||
Usage: "link common configurations to module configuration",
|
||||
Action: link.action,
|
||||
@@ -21,16 +20,16 @@ var link linkCommand
|
||||
|
||||
type linkCommand struct{}
|
||||
|
||||
func (g linkCommand) action(ctx *cli.Context) {
|
||||
func (g linkCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
moduleName := ctx.Args().Get(1)
|
||||
|
||||
if err := service.Config.LinkCommonConfigToModule(configName, moduleName); err != nil {
|
||||
utils.PrintError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2,16 +2,15 @@ package common_config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Remove() cli.Command {
|
||||
return cli.Command{
|
||||
func Remove() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "remove",
|
||||
Usage: "remove common configurations",
|
||||
Action: remove.action,
|
||||
@@ -23,29 +22,25 @@ var remove removeCommand
|
||||
|
||||
type removeCommand struct{}
|
||||
|
||||
func (g removeCommand) action(ctx *cli.Context) {
|
||||
func (g removeCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
|
||||
if configName == "" {
|
||||
utils.PrintError(errors.New("empty common config name"))
|
||||
return
|
||||
return errors.New("empty common config name")
|
||||
}
|
||||
|
||||
config, err := service.Config.GetCommonConfigByName(configName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
links, deleted, err := service.Config.DeleteCommonConfig(config.Id)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if deleted {
|
||||
@@ -53,4 +48,5 @@ func (g removeCommand) action(ctx *cli.Context) {
|
||||
} else {
|
||||
fmt.Printf("config [%s] not deleted, need unlink in next modules:\n%v\n", config.Name, links)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package common_config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/sjson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/cfg"
|
||||
"isp-ctl/command/utils"
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Set() cli.Command {
|
||||
return cli.Command{
|
||||
func Set() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set common configurations",
|
||||
Action: set.action,
|
||||
@@ -25,10 +25,9 @@ var set setCommand
|
||||
|
||||
type setCommand struct{}
|
||||
|
||||
func (g setCommand) action(ctx *cli.Context) {
|
||||
func (g setCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
@@ -36,14 +35,12 @@ func (g setCommand) action(ctx *cli.Context) {
|
||||
changeObject := ctx.Args().Get(2)
|
||||
|
||||
if configName == "" {
|
||||
utils.PrintError(errors.New("empty config name"))
|
||||
return
|
||||
return errors.New("empty config name")
|
||||
}
|
||||
|
||||
mapConfigByName, err := service.Config.GetMapNameCommonConfig()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
config, ok := mapConfigByName[configName]
|
||||
@@ -55,29 +52,26 @@ func (g setCommand) action(ctx *cli.Context) {
|
||||
|
||||
pathObject, err = utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
changeObject, err = utils.CheckChangeObject(changeObject)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
utils.CreateUpdateCommonConfig(changeObject, config)
|
||||
return utils.CreateUpdateCommonConfig(changeObject, config)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(config.Data)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
changeArgument := utils.ParseSetObject(changeObject)
|
||||
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
|
||||
utils.PrintError(err)
|
||||
return err
|
||||
} else {
|
||||
utils.CreateUpdateCommonConfig(stringToChange, config)
|
||||
return utils.CreateUpdateCommonConfig(stringToChange, config)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
package common_config
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func UnLink() cli.Command {
|
||||
return cli.Command{
|
||||
func UnLink() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "unlink",
|
||||
Usage: "unlink common configurations from module configuration",
|
||||
Action: unlink.action,
|
||||
@@ -21,16 +20,16 @@ var unlink unlinkCommand
|
||||
|
||||
type unlinkCommand struct{}
|
||||
|
||||
func (g unlinkCommand) action(ctx *cli.Context) {
|
||||
func (g unlinkCommand) action(ctx *cli.Context) error {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
configName := ctx.Args().First()
|
||||
moduleName := ctx.Args().Get(1)
|
||||
|
||||
if err := service.Config.UnlinkCommonConfigFromModule(configName, moduleName); err != nil {
|
||||
utils.PrintError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user