fix(bash complete)

This commit is contained in:
DeniskaRediska committed 2019-08-23 16:00:00 +03:00
1 parent 6155ebf062
commit d1558438cf
18 files changed
+305 -261

No files matched your search

+12 -105
View File
@@ -4,65 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/codegangsta/cli"
"github.com/integration-system/isp-lib/http"
"github.com/valyala/fasthttp"
"isp-ctl/cfg"
"isp-ctl/flag"
"isp-ctl/service"
"strings"
)
func checkFlags(c *cli.Context) error {
var (
uuid, host string
color bool
)
colorFlag := strings.Split(flag.Color.Name, ", ")
if c.GlobalBool(colorFlag[0]) != false {
color = true
} else {
color = c.GlobalBool(colorFlag[1])
}
service.ColorService.Enable = color
service.UnsafeService.Enable = c.GlobalBool(flag.Unsafe.Name)
hostFlag := strings.Split(flag.Host.Name, ", ")
if c.GlobalString(hostFlag[0]) != "" {
host = c.GlobalString(hostFlag[0])
} else {
host = c.GlobalString(hostFlag[1])
}
uuidFlag := strings.Split(flag.Uuid.Name, ", ")
if c.GlobalString(uuidFlag[0]) != "" {
uuid = c.GlobalString(uuidFlag[0])
} else {
uuid = c.GlobalString(uuidFlag[1])
}
if uuid == "" || host == "" {
if configuration, err := service.YamlService.Parse(); err != nil {
return err
} else {
if uuid == "" {
uuid = configuration.InstanceUuid
}
if host == "" {
host = configuration.GateHost
}
}
}
service.ConfigService.ReceiveConfiguration(host, uuid)
return nil
}
func checkPath(pathObject string) (string, bool) {
func checkPath(pathObject string) (string, error) {
str := strings.Split(pathObject, ".")
pathObject = ""
if len(str) == 1 || str[0] != "" {
printError(errors.New("path must start with '.'"))
return pathObject, false
return pathObject, errors.New("path must start with '.'")
}
for key, value := range str {
if key == 0 {
@@ -74,7 +25,15 @@ func checkPath(pathObject string) (string, bool) {
}
pathObject = fmt.Sprintf("%s.%s", pathObject, value)
}
return pathObject, true
return pathObject, nil
}
func createUpdateConfig(stringToChange string, configuration *cfg.Config) {
if answer, err := service.Config.CreateUpdateConfig(stringToChange, configuration); err != nil {
printError(err)
} else if answer != nil {
printAnswer(answer)
}
}
func printAnswer(data interface{}) {
@@ -85,58 +44,6 @@ func printAnswer(data interface{}) {
}
}
func getModuleConfiguration(moduleName string) (*cfg.Config, []byte) {
if moduleName == "" {
printError(errors.New("need module name. Use 'schema' for get module names"))
return nil, nil
}
moduleConfiguration, err := service.ConfigClient.GetConfigByModuleName(moduleName)
if err != nil {
if errorResponse, ok := err.(http.ErrorResponse); ok {
if errorResponse.StatusCode == fasthttp.StatusNotFound {
printError(errors.New(fmt.Sprintf("module '%s' not found\n", moduleName)))
} else {
printError(err)
}
} else {
printError(err)
}
return nil, nil
}
if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
printError(err)
return nil, nil
} else {
return moduleConfiguration, jsonObject
}
}
func createUpdateConfig(stringToChange string, configuration *cfg.Config) {
newData := make(map[string]interface{})
if stringToChange != "" {
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
printError(err)
return
}
}
if ok, err := service.UnsafeService.CheckConfigurationSchema(configuration.ModuleId, newData); err != nil {
printError(err)
return
} else if !ok {
return
}
configuration.Data = newData
if resp, err := service.ConfigClient.CreateUpdateConfig(*configuration); err != nil {
printError(err)
} else {
printAnswer(resp.Data)
}
}
func printError(err error) {
fmt.Println("ERROR", err)
fmt.Println("ERROR:", err)
}