add 'contain' command for common configs
add flag 'full' for 'get' command update bash complete
This commit is contained in:
1 parent
1a3458ebdd
commit
8b8815d2f2
21 files changed
+348
-54
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user