add 'contain' command for common configs

add flag 'full' for 'get' command
update bash complete
This commit is contained in:
DeniskaRediska committed 2019-10-30 14:58:50 +03:00
1 parent 1a3458ebdd
commit 8b8815d2f2
21 files changed
+348 -54

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ func CommonConfig() cli.Command {
commonConfig.Remove(),
commonConfig.Link(),
commonConfig.UnLink(),
commonConfig.Contain(),
},
}
}
+57
View File
@@ -0,0 +1,57 @@
package commonConfig
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Contain() cli.Command {
return cli.Command{
Name: "contain",
Usage: "availability common configuration in module",
Action: contain.action,
BashComplete: bash.CommonConfig.ConfigName,
}
}
var contain containCommand
type containCommand struct{}
func (g containCommand) action(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
}
ccName := ctx.Args().First()
if ccName == "" {
utils.PrintError(errors.New("empty common config name"))
return
}
commonConfigs, err := service.Config.GetMapCommonConfigByName()
if err != nil {
utils.PrintError(err)
return
}
config, ok := commonConfigs[ccName]
if !ok {
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return
}
links, err := service.Config.GetLinksCommonConfig(config.Id)
if err != nil {
utils.PrintError(err)
} else {
fmt.Printf("%v\n", links)
}
}
+2 -2
View File
@@ -16,7 +16,7 @@ func Delete() cli.Command {
Name: "delete",
Usage: "set common configurations",
Action: deleteComm.action,
BashComplete: bash.CommonConfig.GetSetDelete,
BashComplete: bash.CommonConfig.ConfigName_ConfigData,
}
}
@@ -52,7 +52,7 @@ func (g deleteCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[ccName]
if !ok {
utils.PrintError(errors.Errorf("common config %s not found", ccName))
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return
}
+2 -2
View File
@@ -16,7 +16,7 @@ func Get() cli.Command {
Name: "get",
Usage: "get common configurations",
Action: get.action,
BashComplete: bash.CommonConfig.GetSetDelete,
BashComplete: bash.CommonConfig.ConfigName_ConfigData,
}
}
@@ -55,7 +55,7 @@ func (g getCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[ccName]
if !ok {
utils.PrintError(errors.Errorf("common config %s not found", ccName))
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return
}
+3 -3
View File
@@ -15,7 +15,7 @@ func Link() cli.Command {
Name: "link",
Usage: "link common configurations to module configuration",
Action: link.action,
BashComplete: bash.CommonConfig.LinkUnlink,
BashComplete: bash.CommonConfig.ConfigName_ModuleName,
}
}
@@ -50,11 +50,11 @@ func (g linkCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[configName]
if !ok {
utils.PrintError(errors.Errorf("common config %s not found", configName))
utils.PrintError(errors.Errorf("common config [%s] not found", configName))
return
}
moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
+9 -4
View File
@@ -15,7 +15,7 @@ func Remove() cli.Command {
Name: "remove",
Usage: "remove common configurations",
Action: remove.action,
BashComplete: bash.CommonConfig.Remove,
BashComplete: bash.CommonConfig.ConfigName,
}
}
@@ -44,13 +44,18 @@ func (g removeCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[ccName]
if !ok {
utils.PrintError(errors.Errorf("common config %s not found", ccName))
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
return
}
if deleted, err := service.Config.DeleteCommonConfig(config.Id); err != nil {
links, deleted, err := service.Config.DeleteCommonConfig(config.Id)
if err != nil {
utils.PrintError(err)
return
}
if deleted {
fmt.Printf("config [%s] deleted", config.Name)
} else {
fmt.Printf("count deleted config: %d\n", deleted)
fmt.Printf("config [%s] not deleted, need unlink in next modules:\n%v\n", config.Name, links)
}
}
+1 -1
View File
@@ -19,7 +19,7 @@ func Set() cli.Command {
Name: "set",
Usage: "set common configurations",
Action: set.action,
BashComplete: bash.CommonConfig.GetSetDelete,
BashComplete: bash.CommonConfig.ConfigName_ConfigData,
}
}
+3 -3
View File
@@ -15,7 +15,7 @@ func UnLink() cli.Command {
Name: "unlink",
Usage: "unlink common configurations from module configuration",
Action: unlink.action,
BashComplete: bash.CommonConfig.LinkUnlink,
BashComplete: bash.CommonConfig.ConfigName_ModuleName,
}
}
@@ -50,11 +50,11 @@ func (g unlinkCommand) action(ctx *cli.Context) {
config, ok := commonConfigs[configName]
if !ok {
utils.PrintError(errors.Errorf("common config %s not found", configName))
utils.PrintError(errors.Errorf("common config [%s] not found", configName))
return
}
moduleConfig, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
moduleConfig, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
+9 -2
View File
@@ -1,6 +1,7 @@
package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/tidwall/sjson"
"isp-ctl/bash"
@@ -14,7 +15,7 @@ func Delete() cli.Command {
Name: "delete",
Usage: "delete configuration by module_name",
Action: deleteComm.action,
BashComplete: bash.Module.GetSetDelete,
BashComplete: bash.Module.ModuleName_ModuleData,
}
}
@@ -30,7 +31,7 @@ func (d deleteCommand) action(ctx *cli.Context) {
moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
@@ -45,6 +46,12 @@ func (d deleteCommand) action(ctx *cli.Context) {
if pathObject == "" {
utils.CreateUpdateConfig("", moduleConfiguration)
} else {
jsonObject, err := json.Marshal(moduleConfiguration.Data)
if err != nil {
utils.PrintError(err)
return
}
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
utils.PrintError(err)
return
+20 -3
View File
@@ -1,6 +1,7 @@
package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"isp-ctl/bash"
"isp-ctl/command/utils"
@@ -13,7 +14,10 @@ func Get() cli.Command {
Name: "get",
Usage: "get configuration by module_name",
Action: get.action,
BashComplete: bash.Module.GetSetDelete,
BashComplete: bash.Module.ModuleName_ModuleData,
Flags: []cli.Flag{
flag.WithCommonConfig,
},
}
}
@@ -29,12 +33,20 @@ func (g getCommand) action(ctx *cli.Context) {
moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
config, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
}
data := config.Data
if ctx.Bool(flag.WithCommonConfig.Name) {
if data, err = service.Config.CompileDataWithCommonConfigs(data, config.CommonConfigs); err != nil {
utils.PrintError(err)
return
}
}
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
@@ -42,8 +54,13 @@ func (g getCommand) action(ctx *cli.Context) {
}
if pathObject == "" {
utils.PrintAnswer(moduleConfiguration.Data)
utils.PrintAnswer(data)
} else {
jsonObject, err := json.Marshal(data)
if err != nil {
utils.PrintError(err)
return
}
utils.CheckObject(jsonObject, pathObject)
}
}
+3 -3
View File
@@ -20,7 +20,7 @@ func Schema() cli.Command {
Flags: []cli.Flag{
flag.OutPrint,
},
BashComplete: bash.Module.Schema,
BashComplete: bash.Module.ModuleName,
}
}
@@ -46,13 +46,13 @@ func (s schemaCommand) action(ctx *cli.Context) {
s.printHtml(schema)
default:
utils.PrintError(errors.Errorf(
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
"invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
}
}
}
func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
if configuration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName); err != nil {
if configuration, err := service.Config.GetConfigurationByModuleName(moduleName); err != nil {
utils.PrintError(err)
return nil
} else if schema, err := service.Config.GetSchemaByModuleId(configuration.ModuleId); err != nil {
+9 -2
View File
@@ -1,6 +1,7 @@
package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
@@ -17,7 +18,7 @@ func Set() cli.Command {
Name: "set",
Usage: "set configuration by module_name",
Action: set.action,
BashComplete: bash.Module.GetSetDelete,
BashComplete: bash.Module.ModuleName_ModuleData,
}
}
@@ -35,7 +36,7 @@ func (s setCommand) action(ctx *cli.Context) {
pathObject := ctx.Args().Get(1)
changeObject := ctx.Args().Get(2)
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
@@ -64,6 +65,12 @@ func (s setCommand) action(ctx *cli.Context) {
utils.CreateUpdateConfig(changeObject, moduleConfiguration)
return
} else {
jsonObject, err := json.Marshal(moduleConfiguration.Data)
if err != nil {
utils.PrintError(err)
return
}
changeArgument := utils.ParseSetObject(changeObject)
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
utils.PrintError(err)