update(ref bash complete)
This commit is contained in:
1 parent
93071eef5b
commit
1a3458ebdd
14 files changed
+148
-200
No files matched your search
@@ -1,52 +0,0 @@
|
||||
package bash
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/integration-system/bellows"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
var (
|
||||
ModuleNameAndConfigurationPath = bashAction{enableConfigurationBash: true}
|
||||
ModuleName = bashAction{enableConfigurationBash: false}
|
||||
)
|
||||
|
||||
type (
|
||||
bashAction struct{ enableConfigurationBash bool }
|
||||
)
|
||||
|
||||
func (b bashAction) Complete(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch ctx.NArg() {
|
||||
case 0:
|
||||
b.moduleNameHelper()
|
||||
case 1:
|
||||
if b.enableConfigurationBash {
|
||||
b.configurationPathHelper(ctx.Args().First(), ctx.Args().Get(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bashAction) moduleNameHelper() {
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, module := range arrayOfModules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bashAction) configurationPathHelper(moduleName, path string) {
|
||||
if moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName); err != nil {
|
||||
return
|
||||
} else {
|
||||
for key, _ := range bellows.Flatten(moduleConfiguration.Data) {
|
||||
fmt.Printf(".%v\n", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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) LinkUnlink(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) GetSetDelete(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) Remove(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package bash
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/integration-system/bellows"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
var Module module
|
||||
|
||||
type module struct{}
|
||||
|
||||
func (module) GetSetDelete(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch ctx.NArg() {
|
||||
case 0:
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, module := range arrayOfModules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
if moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(ctx.Args().Get(1)); err != nil {
|
||||
return
|
||||
} else {
|
||||
for key, _ := range bellows.Flatten(moduleConfiguration.Data) {
|
||||
fmt.Printf(".%v\n", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (module) Schema(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch ctx.NArg() {
|
||||
case 0:
|
||||
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, module := range arrayOfModules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user