add(bash complete)

This commit is contained in:
DeniskaRediska committed 2019-08-21 19:10:24 +03:00
1 parent f32d9a80b0
commit 1f794377e5
8 files changed
+81 -16

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
## v1.2.0
* add new command `schema`
* add bash complete
## v1.1.0
* fix status response
* add checking schema to set configuration
Generated
+13 -3
View File
@@ -32,6 +32,14 @@
revision = "6c65a5562fc06764971b7c5d05c76c75e84bdbf7"
version = "v1.3.2"
[[projects]]
branch = "master"
digest = "1:2cf4ff28b309c93a52b3329c7a22d5375b137249d4ed63c9d40707a1b253f7df"
name = "github.com/integration-system/bellows"
packages = ["."]
pruneopts = "UT"
revision = "244325e8836c364c86f308e3aef7e979cb007114"
[[projects]]
branch = "master"
digest = "1:abd0cd78d6d27a98080f2b2a7fd39bb2f3d3eef6aa20c720093129f04fb41d78"
@@ -41,7 +49,7 @@
revision = "368713356c71961354e09ab9b734740ebdd94784"
[[projects]]
digest = "1:cd9785ed4d12c737f23ec65b08fffa4e235cbf8689290211dd95eeb0f1ae7e15"
digest = "1:ecb402b81b0ed58f59ee14a1587f94c9cef1d8710f0eac3e1cbbbc2cb254f8e8"
name = "github.com/integration-system/isp-lib"
packages = [
"config/schema",
@@ -51,8 +59,8 @@
"utils",
]
pruneopts = "UT"
revision = "d2cc77b8fb8648ae7f8efdf1d1b834e8e57b56d7"
version = "v1.5.2"
revision = "d8ea213ec2182662432624bf09cf6726b56f12c4"
version = "v1.6.0"
[[projects]]
branch = "master"
@@ -316,8 +324,10 @@
analyzer-version = 1
input-imports = [
"github.com/codegangsta/cli",
"github.com/integration-system/bellows",
"github.com/integration-system/isp-lib/config/schema",
"github.com/integration-system/isp-lib/http",
"github.com/integration-system/isp-lib/logger",
"github.com/integration-system/isp-lib/structure",
"github.com/olekukonko/tablewriter",
"github.com/tidwall/gjson",
+51
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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,
}
}
+1 -2
View File
@@ -27,14 +27,13 @@ func initCommands() {
ispctl [flag...] schema module_name [local_flag]`
app.Version = version
app.Flags = []cli.Flag{
flag.Host,
flag.Uuid,
flag.Color,
flag.Unsafe,
}
app.EnableBashCompletion = true
app.Commands = []cli.Command{
command.Status(),
command.Get(),