Files
ispctl/bash/common_config.go
T
DeniskaRediska 8b8815d2f2 add 'contain' command for common configs
add flag 'full' for 'get' command
update bash complete
2019-10-30 14:58:50 +03:00

76 lines
1.5 KiB
Go

package bash
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/integration-system/bellows"
"isp-ctl/flag"
"isp-ctl/service"
)
var CommonConfig commonConfig
type commonConfig struct{}
func (commonConfig) ConfigName_ModuleName(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil {
return
}
commonConfigs, err := service.Config.GetMapCommonConfigByName()
if err != nil {
return
}
switch ctx.NArg() {
case 0:
for _, config := range commonConfigs {
fmt.Println(config.Name)
}
case 1:
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
return
} else {
for _, module := range arrayOfModules {
fmt.Println(module.Name)
}
}
}
}
func (commonConfig) ConfigName_ConfigData(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil {
return
}
commonConfigs, err := service.Config.GetMapCommonConfigByName()
if err != nil {
return
}
switch ctx.NArg() {
case 0:
for _, config := range commonConfigs {
fmt.Println(config.Name)
}
case 1:
if config, ok := commonConfigs[ctx.Args().First()]; ok {
for key, _ := range bellows.Flatten(config.Data) {
fmt.Printf(".%v\n", key)
}
}
}
}
func (commonConfig) ConfigName(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil {
return
}
commonConfigs, err := service.Config.GetMapCommonConfigByName()
if err != nil {
return
}
switch ctx.NArg() {
case 0:
for _, config := range commonConfigs {
fmt.Println(config.Name)
}
}
}