add 'contain' command for common configs
add flag 'full' for 'get' command update bash complete
This commit is contained in:
1 parent
1a3458ebdd
commit
8b8815d2f2
21 files changed
+348
-54
No files matched your search
@@ -25,11 +25,13 @@ instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
## Использование
|
||||
```bash
|
||||
ispctl [flag...] status
|
||||
ispctl [flag...] get module_name property_path
|
||||
ispctl [flag...] get module_name property_path [local_flag]
|
||||
ispctl [flag...] set module_name property_path [new_object]
|
||||
ispctl [flag...] delete module_name property_path
|
||||
ispctl [flag...] schema module_name [local_flag]
|
||||
ispctl [flag...] common sub_command
|
||||
```
|
||||
|
||||
## Описание
|
||||
|
||||
| Команды | Описание |
|
||||
@@ -39,6 +41,7 @@ ispctl [flag...] schema module_name [local_flag]
|
||||
| `set` | изменяет объект конфигурации указанного модуля |
|
||||
| `delete` | удаляет объект конфигурации указанного модуля |
|
||||
| `schema` | возвращает схему конфигурации указанного модуля |
|
||||
| `common` | комманда для взаимодействие с общими конфигурациями |
|
||||
| | |
|
||||
|
||||
| Флаги | Параметры | Описание |
|
||||
@@ -51,15 +54,37 @@ ispctl [flag...] schema module_name [local_flag]
|
||||
|
||||
| Аргументы | Описание |
|
||||
|-----------------|-------------------------------------------------------------------------------------------------------------|
|
||||
| `module_name` | Модуль с которым происходит взаимодействие |
|
||||
| `module_name` | Название модуля с которым происходит взаимодействие |
|
||||
| `proprtry_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
|
||||
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
|
||||
| | |
|
||||
|
||||
| Локальные флаги | Параметры | Команды | Описание |
|
||||
|-----------------|-----------|---------|---------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `-o` | string | schema | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
|
||||
| `-full` | bool | get | осуществляет взаимодействие с объектами конфигурации модуля с учетом объектом общих конфигураций, которые имеют связь с модулем |
|
||||
| | | | |
|
||||
|
||||
### sub_command
|
||||
#### common
|
||||
```bash
|
||||
ispctl [flag...] common set config_name property_path [new_object]
|
||||
ispctl [flag...] common get [config_name] property_path
|
||||
ispctl [flag...] common delete config_name property_path
|
||||
ispctl [flag...] common remove config_name
|
||||
ispctl [flag...] common link config_name module_name
|
||||
ispctl [flag...] common unlink config_name module_name
|
||||
ispctl [flag...] common contain config_name
|
||||
```
|
||||
|
||||
| Аргументы | Описание |
|
||||
|-----------------|-------------------------------------------------------------------------------------------------------------|
|
||||
| `config_name` | Названия конфига с которым происходит взаимодействие |
|
||||
| `module_name` | Название модуля с которым происходит взаимодействие |
|
||||
| `proprtry_path` | Путь к объекту конфигурации, при значении `.` работа происходит со всей конфигурацией модуля |
|
||||
| `new_object` | Новый объект, значение должно быть экранировано с помощью `' '`, при отсутсвии ожидается ввод из stdin |
|
||||
| | |
|
||||
|
||||
| Локальные флаги | Параметры | Описание |
|
||||
|-----------------|-----------|--------------------------------------------------------------------------------------------------|
|
||||
| `-o` | string | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
|
||||
| | | |
|
||||
|
||||
## Пример
|
||||
### ispctl status
|
||||
@@ -318,6 +343,106 @@ ispctl schema example -o html
|
||||
|
||||
```
|
||||
|
||||
### ispctl common
|
||||
#### get
|
||||
Возвращает список названий общих конфигураций или, если в первом аргументе указано название общей конфигурации, возвращает объект общей конфигурации по указанному пути
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common get
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
test b c
|
||||
```
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common get test .
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
{
|
||||
"test": null
|
||||
}
|
||||
```
|
||||
#### set
|
||||
Добавляет объект в общую конфигурацию по указанному пути
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common set test .test '{"a":"a","b":"b"}'
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
{
|
||||
"test": {
|
||||
"a": "a",
|
||||
"b": "b"
|
||||
}
|
||||
}
|
||||
```
|
||||
#### delete
|
||||
Удаляет объект из общей конфигурации по указанному пути
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common delete test .test.a
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
{
|
||||
"test": {
|
||||
"b": "b"
|
||||
}
|
||||
}
|
||||
```
|
||||
#### link
|
||||
Связывает 'common_config' к конфигурации модуля по 'module_name'. Возвращает список общих конфигураций, которые связаны с модулем
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common link test module_example
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
[test] [second_common_config]
|
||||
```
|
||||
#### remove
|
||||
Удаляет объект общий конфигурации, если он не связан с конфигурациями модулей. Если общая конфигурация имеет связи, выводит список модулей с которыми установлена связь
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common remove test
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
config [test] not deleted, need unlink in next modules:
|
||||
[module_example]
|
||||
```
|
||||
#### unlink
|
||||
Отвязывает 'common_config' от конфигурации модуля по 'module_name'. Возвращает список общих конфигураций, которые связаны с модулем
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl common unlink test module_example
|
||||
```
|
||||
Ответ
|
||||
Ответ
|
||||
```bash
|
||||
[second_common_config]
|
||||
```
|
||||
#### contain
|
||||
Возвращает список названий модулей, с которыми имеет связь общая конфигурация
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
isp-ctl common contain second_common_config
|
||||
```
|
||||
Ответ
|
||||
Ответ
|
||||
```bash
|
||||
[module_example]
|
||||
```
|
||||
|
||||
### Запрос с флагами
|
||||
Запрос
|
||||
|
||||
@@ -12,7 +12,7 @@ var CommonConfig commonConfig
|
||||
|
||||
type commonConfig struct{}
|
||||
|
||||
func (commonConfig) LinkUnlink(ctx *cli.Context) {
|
||||
func (commonConfig) ConfigName_ModuleName(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (commonConfig) LinkUnlink(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (commonConfig) GetSetDelete(ctx *cli.Context) {
|
||||
func (commonConfig) ConfigName_ConfigData(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func (commonConfig) GetSetDelete(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (commonConfig) Remove(ctx *cli.Context) {
|
||||
func (commonConfig) ConfigName(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
+4
-3
@@ -12,7 +12,7 @@ var Module module
|
||||
|
||||
type module struct{}
|
||||
|
||||
func (module) GetSetDelete(ctx *cli.Context) {
|
||||
func (module) ModuleName_ModuleData(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -26,7 +26,8 @@ func (module) GetSetDelete(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
if moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(ctx.Args().Get(1)); err != nil {
|
||||
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(ctx.Args().Get(1))
|
||||
if err != nil {
|
||||
return
|
||||
} else {
|
||||
for key, _ := range bellows.Flatten(moduleConfiguration.Data) {
|
||||
@@ -36,7 +37,7 @@ func (module) GetSetDelete(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (module) Schema(ctx *cli.Context) {
|
||||
func (module) ModuleName(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
+14
-2
@@ -66,6 +66,18 @@ type ConfigSchema struct {
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type deleted struct {
|
||||
Deleted int
|
||||
type Deleted struct {
|
||||
Deleted bool
|
||||
Links Links
|
||||
}
|
||||
|
||||
type Links map[string][]string
|
||||
|
||||
type identityRequest struct {
|
||||
Id string
|
||||
}
|
||||
|
||||
type CompileConfigs struct {
|
||||
Data map[string]interface{}
|
||||
CommonConfigsIdList []string
|
||||
}
|
||||
@@ -8,4 +8,6 @@ const (
|
||||
getCommonConfigs = "config/common_config/get_configs"
|
||||
createUpdateCommonConfig = "config/common_config/create_update_config"
|
||||
deleteCommonConfig = "config/common_config/delete_config"
|
||||
getLinksCommonConfig = "config/common_config/get_links"
|
||||
compileCommonConfigs = "config/common_config/compile"
|
||||
)
|
||||
+27
-5
@@ -104,13 +104,35 @@ func (c *configClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) DeleteCommonConfig(req []string) (int, error) {
|
||||
response := new(deleted)
|
||||
err := c.cli.Invoke(deleteCommonConfig, callerId, req, response, backend.WithMetadata(c.headers))
|
||||
func (c *configClient) DeleteCommonConfig(id string) (*Deleted, error) {
|
||||
request := identityRequest{Id: id}
|
||||
response := new(Deleted)
|
||||
err := c.cli.Invoke(deleteCommonConfig, callerId, request, response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
return 0, c.errorHandler(err)
|
||||
return nil, c.errorHandler(err)
|
||||
} else {
|
||||
return response.Deleted, nil
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) GetLinksCommonConfig(id string) (*Links, error) {
|
||||
request := identityRequest{Id: id}
|
||||
response := new(Links)
|
||||
err := c.cli.Invoke(getLinksCommonConfig, callerId, request, response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
return nil, c.errorHandler(err)
|
||||
} else {
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *configClient) CompileCommonConfigs(request CompileConfigs) (map[string]interface{}, error) {
|
||||
response := make(map[string]interface{})
|
||||
err := c.cli.Invoke(compileCommonConfigs, callerId, request, &response, backend.WithMetadata(c.headers))
|
||||
if err != nil {
|
||||
return nil, c.errorHandler(err)
|
||||
} else {
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ func CommonConfig() cli.Command {
|
||||
commonConfig.Remove(),
|
||||
commonConfig.Link(),
|
||||
commonConfig.UnLink(),
|
||||
commonConfig.Contain(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package commonConfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
)
|
||||
|
||||
func Contain() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "contain",
|
||||
Usage: "availability common configuration in module",
|
||||
Action: contain.action,
|
||||
BashComplete: bash.CommonConfig.ConfigName,
|
||||
}
|
||||
}
|
||||
|
||||
var contain containCommand
|
||||
|
||||
type containCommand struct{}
|
||||
|
||||
func (g containCommand) action(ctx *cli.Context) {
|
||||
if err := flag.CheckGlobal(ctx); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ccName := ctx.Args().First()
|
||||
|
||||
if ccName == "" {
|
||||
utils.PrintError(errors.New("empty common config name"))
|
||||
return
|
||||
}
|
||||
|
||||
commonConfigs, err := service.Config.GetMapCommonConfigByName()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
config, ok := commonConfigs[ccName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
|
||||
return
|
||||
}
|
||||
|
||||
links, err := service.Config.GetLinksCommonConfig(config.Id)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
} else {
|
||||
fmt.Printf("%v\n", links)
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ func Delete() cli.Command {
|
||||
Name: "delete",
|
||||
Usage: "set common configurations",
|
||||
Action: deleteComm.action,
|
||||
BashComplete: bash.CommonConfig.GetSetDelete,
|
||||
BashComplete: bash.CommonConfig.ConfigName_ConfigData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (g deleteCommand) action(ctx *cli.Context) {
|
||||
|
||||
config, ok := commonConfigs[ccName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config %s not found", ccName))
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ func Get() cli.Command {
|
||||
Name: "get",
|
||||
Usage: "get common configurations",
|
||||
Action: get.action,
|
||||
BashComplete: bash.CommonConfig.GetSetDelete,
|
||||
BashComplete: bash.CommonConfig.ConfigName_ConfigData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (g getCommand) action(ctx *cli.Context) {
|
||||
|
||||
config, ok := commonConfigs[ccName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config %s not found", ccName))
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ func Link() cli.Command {
|
||||
Name: "link",
|
||||
Usage: "link common configurations to module configuration",
|
||||
Action: link.action,
|
||||
BashComplete: bash.CommonConfig.LinkUnlink,
|
||||
BashComplete: bash.CommonConfig.ConfigName_ModuleName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ func (g linkCommand) action(ctx *cli.Context) {
|
||||
|
||||
config, ok := commonConfigs[configName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config %s not found", configName))
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", configName))
|
||||
return
|
||||
}
|
||||
|
||||
moduleConfiguration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
|
||||
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
|
||||
@@ -15,7 +15,7 @@ func Remove() cli.Command {
|
||||
Name: "remove",
|
||||
Usage: "remove common configurations",
|
||||
Action: remove.action,
|
||||
BashComplete: bash.CommonConfig.Remove,
|
||||
BashComplete: bash.CommonConfig.ConfigName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,13 +44,18 @@ func (g removeCommand) action(ctx *cli.Context) {
|
||||
|
||||
config, ok := commonConfigs[ccName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config %s not found", ccName))
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", ccName))
|
||||
return
|
||||
}
|
||||
|
||||
if deleted, err := service.Config.DeleteCommonConfig(config.Id); err != nil {
|
||||
links, deleted, err := service.Config.DeleteCommonConfig(config.Id)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
if deleted {
|
||||
fmt.Printf("config [%s] deleted", config.Name)
|
||||
} else {
|
||||
fmt.Printf("count deleted config: %d\n", deleted)
|
||||
fmt.Printf("config [%s] not deleted, need unlink in next modules:\n%v\n", config.Name, links)
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ func Set() cli.Command {
|
||||
Name: "set",
|
||||
Usage: "set common configurations",
|
||||
Action: set.action,
|
||||
BashComplete: bash.CommonConfig.GetSetDelete,
|
||||
BashComplete: bash.CommonConfig.ConfigName_ConfigData,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ func UnLink() cli.Command {
|
||||
Name: "unlink",
|
||||
Usage: "unlink common configurations from module configuration",
|
||||
Action: unlink.action,
|
||||
BashComplete: bash.CommonConfig.LinkUnlink,
|
||||
BashComplete: bash.CommonConfig.ConfigName_ModuleName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,11 +50,11 @@ func (g unlinkCommand) action(ctx *cli.Context) {
|
||||
|
||||
config, ok := commonConfigs[configName]
|
||||
if !ok {
|
||||
utils.PrintError(errors.Errorf("common config %s not found", configName))
|
||||
utils.PrintError(errors.Errorf("common config [%s] not found", configName))
|
||||
return
|
||||
}
|
||||
|
||||
moduleConfig, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
|
||||
moduleConfig, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
|
||||
+9
-2
@@ -1,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/tidwall/sjson"
|
||||
"isp-ctl/bash"
|
||||
@@ -14,7 +15,7 @@ func Delete() cli.Command {
|
||||
Name: "delete",
|
||||
Usage: "delete configuration by module_name",
|
||||
Action: deleteComm.action,
|
||||
BashComplete: bash.Module.GetSetDelete,
|
||||
BashComplete: bash.Module.ModuleName_ModuleData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ func (d deleteCommand) action(ctx *cli.Context) {
|
||||
moduleName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
|
||||
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
@@ -45,6 +46,12 @@ func (d deleteCommand) action(ctx *cli.Context) {
|
||||
if pathObject == "" {
|
||||
utils.CreateUpdateConfig("", moduleConfiguration)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(moduleConfiguration.Data)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
|
||||
+20
-3
@@ -1,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/codegangsta/cli"
|
||||
"isp-ctl/bash"
|
||||
"isp-ctl/command/utils"
|
||||
@@ -13,7 +14,10 @@ func Get() cli.Command {
|
||||
Name: "get",
|
||||
Usage: "get configuration by module_name",
|
||||
Action: get.action,
|
||||
BashComplete: bash.Module.GetSetDelete,
|
||||
BashComplete: bash.Module.ModuleName_ModuleData,
|
||||
Flags: []cli.Flag{
|
||||
flag.WithCommonConfig,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +33,20 @@ func (g getCommand) action(ctx *cli.Context) {
|
||||
moduleName := ctx.Args().First()
|
||||
pathObject := ctx.Args().Get(1)
|
||||
|
||||
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
|
||||
config, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
data := config.Data
|
||||
if ctx.Bool(flag.WithCommonConfig.Name) {
|
||||
if data, err = service.Config.CompileDataWithCommonConfigs(data, config.CommonConfigs); err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
pathObject, err = utils.CheckPath(pathObject)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
@@ -42,8 +54,13 @@ func (g getCommand) action(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
if pathObject == "" {
|
||||
utils.PrintAnswer(moduleConfiguration.Data)
|
||||
utils.PrintAnswer(data)
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
utils.CheckObject(jsonObject, pathObject)
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -20,7 +20,7 @@ func Schema() cli.Command {
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrint,
|
||||
},
|
||||
BashComplete: bash.Module.Schema,
|
||||
BashComplete: bash.Module.ModuleName,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ func (s schemaCommand) action(ctx *cli.Context) {
|
||||
s.printHtml(schema)
|
||||
default:
|
||||
utils.PrintError(errors.Errorf(
|
||||
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
|
||||
"invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
|
||||
if configuration, _, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName); err != nil {
|
||||
if configuration, err := service.Config.GetConfigurationByModuleName(moduleName); err != nil {
|
||||
utils.PrintError(err)
|
||||
return nil
|
||||
} else if schema, err := service.Config.GetSchemaByModuleId(configuration.ModuleId); err != nil {
|
||||
|
||||
+9
-2
@@ -1,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/sjson"
|
||||
@@ -17,7 +18,7 @@ func Set() cli.Command {
|
||||
Name: "set",
|
||||
Usage: "set configuration by module_name",
|
||||
Action: set.action,
|
||||
BashComplete: bash.Module.GetSetDelete,
|
||||
BashComplete: bash.Module.ModuleName_ModuleData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ func (s setCommand) action(ctx *cli.Context) {
|
||||
pathObject := ctx.Args().Get(1)
|
||||
changeObject := ctx.Args().Get(2)
|
||||
|
||||
moduleConfiguration, jsonObject, err := service.Config.GetConfigurationAndJsonByModuleName(moduleName)
|
||||
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
@@ -64,6 +65,12 @@ func (s setCommand) action(ctx *cli.Context) {
|
||||
utils.CreateUpdateConfig(changeObject, moduleConfiguration)
|
||||
return
|
||||
} else {
|
||||
jsonObject, err := json.Marshal(moduleConfiguration.Data)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
changeArgument := utils.ParseSetObject(changeObject)
|
||||
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
|
||||
utils.PrintError(err)
|
||||
|
||||
@@ -18,6 +18,9 @@ const (
|
||||
outPrintName = "o"
|
||||
OutPrintJsonValue = "json"
|
||||
OutPrintHtmlValue = "html"
|
||||
|
||||
withCommonConfigName = "full"
|
||||
withCommonConfigUsage = "compile data with common configs"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+2
-1
@@ -13,7 +13,8 @@ var (
|
||||
Color = cli.BoolFlag{Name: colorName, Usage: colorUsage}
|
||||
Unsafe = cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
|
||||
//---local---
|
||||
OutPrint = cli.StringFlag{Name: outPrintName, Usage: outPrintUsage, Value: OutPrintJsonValue}
|
||||
OutPrint = cli.StringFlag{Name: outPrintName, Usage: outPrintUsage, Value: OutPrintJsonValue}
|
||||
WithCommonConfig = cli.BoolFlag{Name: withCommonConfigName, Usage: withCommonConfigUsage}
|
||||
)
|
||||
|
||||
func CheckGlobal(c *cli.Context) error {
|
||||
|
||||
+43
-9
@@ -25,23 +25,21 @@ func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
|
||||
return configClient.GetAvailableConfigs()
|
||||
}
|
||||
|
||||
func (c configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) {
|
||||
func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) {
|
||||
if moduleName == "" {
|
||||
return nil, nil, errors.New("need module name")
|
||||
return nil, errors.New("need module name")
|
||||
}
|
||||
|
||||
if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil {
|
||||
if errorStatus, ok := status.FromError(err); ok {
|
||||
switch errorStatus.Code() {
|
||||
case codes.NotFound:
|
||||
return nil, nil, errors.Errorf("module '%s' not found", moduleName)
|
||||
return nil, errors.Errorf("module [%s] not found", moduleName)
|
||||
}
|
||||
}
|
||||
return nil, nil, err
|
||||
} else if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
} else {
|
||||
return moduleConfiguration, jsonObject, nil
|
||||
return moduleConfiguration, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,8 +110,44 @@ func (c configService) CreateUpdateCommonConfig(stringToChange string, config cf
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) DeleteCommonConfig(configId string) (int, error) {
|
||||
return configClient.DeleteCommonConfig([]string{configId})
|
||||
func (c configService) DeleteCommonConfig(configId string) ([]string, bool, error) {
|
||||
deletedInfo, err := configClient.DeleteCommonConfig(configId)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
arrayOfModuleName := make([]string, 0)
|
||||
for moduleName := range deletedInfo.Links {
|
||||
arrayOfModuleName = append(arrayOfModuleName, moduleName)
|
||||
}
|
||||
return arrayOfModuleName, deletedInfo.Deleted, nil
|
||||
}
|
||||
|
||||
func (c configService) GetLinksCommonConfig(configId string) ([]string, error) {
|
||||
link, err := configClient.GetLinksCommonConfig(configId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arrayOfModuleName := make([]string, 0)
|
||||
for moduleName := range *link {
|
||||
arrayOfModuleName = append(arrayOfModuleName, moduleName)
|
||||
}
|
||||
return arrayOfModuleName, nil
|
||||
}
|
||||
|
||||
func (c configService) CompileDataWithCommonConfigs(
|
||||
data map[string]interface{}, commonConfigs []string) (map[string]interface{}, error) {
|
||||
|
||||
req := cfg.CompileConfigs{
|
||||
Data: data,
|
||||
CommonConfigsIdList: commonConfigs,
|
||||
}
|
||||
var err error
|
||||
data, err = configClient.CompileCommonConfigs(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c configService) checkSchema(moduleId string, object map[string]interface{}) (bool, error) {
|
||||
|
||||
Reference in new issue
Block a user