add(bash complete)
This commit is contained in:
1 parent
f32d9a80b0
commit
1f794377e5
8 files changed
+81
-16
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/integration-system/bellows"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
var (
|
||||
bash = bashAction{enableConfigurationBash: true}
|
||||
bashSchema = bashAction{enableConfigurationBash: false}
|
||||
)
|
||||
|
||||
type (
|
||||
bashAction struct{ enableConfigurationBash bool }
|
||||
)
|
||||
|
||||
func (b bashAction) run(ctx *cli.Context) {
|
||||
if err := checkFlags(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch ctx.NArg() {
|
||||
case 0:
|
||||
b.moduleNameHelper()
|
||||
case 1:
|
||||
if b.enableConfigurationBash {
|
||||
b.configurationHelper(ctx.Args().First(), ctx.Args().Get(1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bashAction) moduleNameHelper() {
|
||||
if arrayOfModules, err := service.ConfigClient.GetAvailableConfigs(); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, module := range arrayOfModules {
|
||||
fmt.Println(module.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bashAction) configurationHelper(moduleName, path string) {
|
||||
moduleConfiguration, _ := getModuleConfiguration(moduleName)
|
||||
if moduleConfiguration == nil {
|
||||
return
|
||||
}
|
||||
for key, _ := range bellows.Flatten(moduleConfiguration.Data) {
|
||||
fmt.Printf(".%v\n", key)
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -7,9 +7,10 @@ import (
|
||||
|
||||
func Delete() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "delete configuration by module_name",
|
||||
Action: deleteComm.action,
|
||||
Name: "delete",
|
||||
Usage: "delete configuration by module_name",
|
||||
Action: deleteComm.action,
|
||||
BashComplete: bash.run,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -10,9 +10,10 @@ import (
|
||||
|
||||
func Get() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "get",
|
||||
Usage: "get configuration by module_name",
|
||||
Action: get.action,
|
||||
Name: "get",
|
||||
Usage: "get configuration by module_name",
|
||||
Action: get.action,
|
||||
BashComplete: bash.run,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
convert "github.com/integration-system/isp-lib/config/schema"
|
||||
"html/template"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
@@ -18,6 +19,7 @@ func Schema() cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrint,
|
||||
},
|
||||
BashComplete: bashSchema.run,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +38,6 @@ func (s schemaCommand) action(c *cli.Context) {
|
||||
schema := make(map[string]interface{})
|
||||
schema["title"] = moduleName
|
||||
schema["schema"] = schemaConfig
|
||||
|
||||
switch c.String(flag.OutPrint.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
printAnswer(schema)
|
||||
@@ -56,7 +57,7 @@ func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
|
||||
printError(err)
|
||||
return nil
|
||||
} else {
|
||||
return schema.Schema
|
||||
return convert.DereferenceSchema(schema.Schema)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -12,9 +12,10 @@ import (
|
||||
|
||||
func Set() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set configuration by module_name",
|
||||
Action: set.action,
|
||||
Name: "set",
|
||||
Usage: "set configuration by module_name",
|
||||
Action: set.action,
|
||||
BashComplete: bash.run,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user