add(new command schema)
This commit is contained in:
1 parent
fcafab05d1
commit
f32d9a80b0
16 files changed
+306
-77
No files matched your search
@@ -1,3 +1,5 @@
|
||||
## v1.2.0
|
||||
* add new command `schema`
|
||||
## v1.1.0
|
||||
* fix status response
|
||||
* add checking schema to set configuration
|
||||
|
||||
Generated
+21
-21
@@ -10,12 +10,12 @@
|
||||
version = "v9"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:b24d38b282bacf9791408a080f606370efa3d364e4b5fd9ba0f7b87786d3b679"
|
||||
digest = "1:ca4df663ad76879ad38dbd736493679cbb1aa596c6d479fd9fc5e959e5ceb4fb"
|
||||
name = "github.com/codegangsta/cli"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
|
||||
version = "v1.20.0"
|
||||
revision = "e6cf83ec39f6e1158ced1927d4ed14578fda8edb"
|
||||
version = "v1.21.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:07f4fafe81587b642166199f41c3edcca12929fcfcc0261b00be5dea2f968f44"
|
||||
@@ -74,7 +74,7 @@
|
||||
version = "v1.1.7"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:823dc0f8e4cdad8d91e6aba4cdd985a035596a8aa02e9d2abf1bec347894c41f"
|
||||
digest = "1:836838f1466d370fc7678c927e5b7473f38ba12c2e571f8eca957bd0a102c2db"
|
||||
name = "github.com/klauspost/compress"
|
||||
packages = [
|
||||
"flate",
|
||||
@@ -82,8 +82,8 @@
|
||||
"zlib",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "23256797d1e4ccac36fad828362cdfef5b3aeb90"
|
||||
version = "v1.7.4"
|
||||
revision = "4030f0cdb60476e7065ab476972fcfd43670cd86"
|
||||
version = "v1.7.6"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:923c4d7194b42e054b2eb8a6c62824ac55e23ececc1c7e48d4da69c971c55954"
|
||||
@@ -110,12 +110,12 @@
|
||||
version = "v0.1.2"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:9b90c7639a41697f3d4ad12d7d67dfacc9a7a4a6e0bbfae4fc72d0da57c28871"
|
||||
digest = "1:36325ebb862e0382f2f14feef409ba9351271b89ada286ae56836c603d43b59c"
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "1311e847b0cb909da63b5fecfb5370aa66236465"
|
||||
version = "v0.0.8"
|
||||
revision = "e1f7b56ace729e4a73a29a6b4fac6cd5fcda7ab3"
|
||||
version = "v0.0.9"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:0356f3312c9bd1cbeda81505b7fd437501d8e778ab66998ef69f00d7f9b3a0d7"
|
||||
@@ -207,7 +207,7 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:14263f971ab2057d9d8e0e47a5c9af0ae482c4d2530c47f86e8a247046d5df8e"
|
||||
digest = "1:9ac1027203be1e5f4bc35bc822f0938d07716f8c83ba5ffd3a331682335ab24b"
|
||||
name = "github.com/valyala/fasthttp"
|
||||
packages = [
|
||||
".",
|
||||
@@ -215,7 +215,7 @@
|
||||
"stackless",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "55ea350c55431331ff77defe5f450331577f64dd"
|
||||
revision = "c5413ffda8a3203d573900b871da46234fcf9466"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:39a425f98fb19427061a693fe6bf0683c9bddec4b25b17067e34fdb465e39cb9"
|
||||
@@ -227,11 +227,11 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:f4e5276a3b356f4692107047fd2890f2fe534f4feeb6b1fd2f6dfbd87f1ccf54"
|
||||
digest = "1:d9464a87e24a9703fd6b9b27b3592559eb7f5886285d724cb0acd62d00a5ddbf"
|
||||
name = "github.com/xeipuuv/gojsonpointer"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "4e3ac2762d5f479393488629ee9370b50873b3a6"
|
||||
revision = "df4f5c81cb3b310899c091852a576ea7d178aedb"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -255,7 +255,7 @@
|
||||
name = "golang.org/x/crypto"
|
||||
packages = ["ssh/terminal"]
|
||||
pruneopts = "UT"
|
||||
revision = "4def268fd1a49955bfb3dda92fe3db4f924f2285"
|
||||
revision = "60c769a6c58655dab1b9adac0d58967dd517cfba"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -263,18 +263,18 @@
|
||||
name = "golang.org/x/net"
|
||||
packages = ["context"]
|
||||
pruneopts = "UT"
|
||||
revision = "ca1201d0de80cfde86cb01aea620983605dfe99b"
|
||||
revision = "74dc4d7220e7acc4e100824340f3e66577424772"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:f99b0e9035cf86cdc14cb2848308e831193d5e19ab9a23a8493cd925bdc3952b"
|
||||
digest = "1:d52ccbb025caf0a2166e0204ed934567b8d0dfdd23a09d947f1f040708888a0a"
|
||||
name = "golang.org/x/sys"
|
||||
packages = [
|
||||
"unix",
|
||||
"windows",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "fc99dfbffb4e5ed5758a37e31dd861afe285406b"
|
||||
revision = "fde4db37ae7ad8191b03d30d27f258b5291ae4e3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
@@ -285,10 +285,10 @@
|
||||
"googleapis/rpc/status",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "c506a9f9061087022822e8da603a52fc387115a8"
|
||||
revision = "24fa4b261c55da65468f2abfdae2b024eef27dfb"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:caa836d207326da987daf8eb4404ef80806fb843056367d2c3c1636f57ede119"
|
||||
digest = "1:42de3e9a8a8d7d0c7dc0e832f03786c3993c6d97b0e4a18268fb0142cd65e247"
|
||||
name = "google.golang.org/grpc"
|
||||
packages = [
|
||||
"codes",
|
||||
@@ -300,8 +300,8 @@
|
||||
"status",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "045159ad57f3781d409358e3ade910a018c16b30"
|
||||
version = "v1.22.1"
|
||||
revision = "6eaf6f47437a6b4e2153a190160ef39a92c7eceb"
|
||||
version = "v1.23.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96"
|
||||
|
||||
@@ -28,16 +28,18 @@ ispctl [flag...] status
|
||||
ispctl [flag...] get module_name property_path
|
||||
ispctl [flag...] set module_name property_path [new_object]
|
||||
ispctl [flag...] delete module_name property_path
|
||||
ispctl [flag...] schema module_name [local_flag]
|
||||
```
|
||||
## Описание
|
||||
|
||||
| Команды | Описание |
|
||||
|-----------|---------------------------------------------------------------------------------------------|
|
||||
| `status` | возвращает доступные конфигурации модулей, их состояния и подключения |
|
||||
| `get` | возвращает объект конфигурации указанного модуля |
|
||||
| `set` | изменяет объект конфигурации указанного модуля |
|
||||
| `delete` | удаляет объект конфигурации указанного модуля |
|
||||
| | |
|
||||
| Команды | Описание |
|
||||
|-------------|---------------------------------------------------------------------------------------------|
|
||||
| `status` | возвращает доступные конфигурации модулей, их состояния и подключения |
|
||||
| `get` | возвращает объект конфигурации указанного модуля |
|
||||
| `set` | изменяет объект конфигурации указанного модуля |
|
||||
| `delete` | удаляет объект конфигурации указанного модуля |
|
||||
| `schema` | возвращает схему конфигурации указанного модуля |
|
||||
| | |
|
||||
|
||||
| Флаги | Параметры | Описание |
|
||||
|-------------|-----------|------------------------------------------------------------------|
|
||||
@@ -54,10 +56,14 @@ ispctl [flag...] delete module_name property_path
|
||||
| `new_object` | Новый объект, должен быть экранирован с помощью `' '`, при отсутсвии ожидается ввод из stdin |
|
||||
| | |
|
||||
|
||||
| Локальные флаги | Параметры | Описание |
|
||||
|-----------------|-----------|--------------------------------------------------------------------------------------------------|
|
||||
| `-o` | string | определяет формат вывода схемы в stdout; по умолчанию `json`; возможные значения `json`, `html` |
|
||||
| | | |
|
||||
|
||||
## Пример
|
||||
### ispctl status
|
||||
`ispctl status [flag...]`
|
||||
`ispctl [flag...] status`
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
@@ -75,7 +81,7 @@ ispctl status
|
||||
```
|
||||
|
||||
### ispctl get
|
||||
`ispctl get [flag...] module_name property_path`
|
||||
`ispctl [flag...] get module_name property_path`
|
||||
* Получение полной конфигурации
|
||||
|
||||
Запрос
|
||||
@@ -122,7 +128,7 @@ ispctl get example .metrics.address
|
||||
```
|
||||
|
||||
### ispctl set
|
||||
`ispctl set [flag...] module_name property_path [new_object]`
|
||||
`ispctl [flag...] set module_name property_path [new_object]`
|
||||
|
||||
При указании `new_object` необходимо его экранировать. При его отсутсвии ожидается ввод из stdin
|
||||
|
||||
@@ -213,7 +219,7 @@ ispctl set example . '{"journal":{"bufferSize":1111,"compress":false,"enable":tr
|
||||
}
|
||||
```
|
||||
### ispctl delete
|
||||
`ispctl delete [flag...] module_name property_path`
|
||||
`ispctl [flag...] delete module_name property_path`
|
||||
* Удаление объекта конфигурации
|
||||
|
||||
Запрос
|
||||
@@ -264,6 +270,55 @@ ispctl delete example .
|
||||
{}
|
||||
```
|
||||
|
||||
### ispctl schema
|
||||
`ispctl [flag...] schema module_name [local_flag]`
|
||||
* Получение схемы конфигурации
|
||||
|
||||
Запрос
|
||||
```bash
|
||||
ispctl schema example
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
{
|
||||
"title": "example"
|
||||
"schema": {
|
||||
"title": "Remote config",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"journal",
|
||||
],
|
||||
...
|
||||
...
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
Запрос
|
||||
```bash
|
||||
ispctl schema example -o html
|
||||
```
|
||||
Ответ
|
||||
```bash
|
||||
<html>
|
||||
<head>
|
||||
...
|
||||
...
|
||||
...
|
||||
<body>
|
||||
<div class="results"></div>
|
||||
<script>
|
||||
var schema = [
|
||||
{"schema":{"required":["journal"]...
|
||||
...
|
||||
...
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Запрос с флагами
|
||||
Запрос
|
||||
```bash
|
||||
|
||||
+19
-14
@@ -2,6 +2,7 @@ package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/integration-system/isp-lib/http"
|
||||
@@ -17,23 +18,23 @@ func checkFlags(c *cli.Context) error {
|
||||
uuid, host string
|
||||
color bool
|
||||
)
|
||||
colorFlag := strings.Split(flag.ColorName, ", ")
|
||||
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.UnsafeName)
|
||||
service.UnsafeService.Enable = c.GlobalBool(flag.Unsafe.Name)
|
||||
|
||||
hostFlag := strings.Split(flag.GateHostName, ", ")
|
||||
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.InstanceUuidName, ", ")
|
||||
uuidFlag := strings.Split(flag.Uuid.Name, ", ")
|
||||
if c.GlobalString(uuidFlag[0]) != "" {
|
||||
uuid = c.GlobalString(uuidFlag[0])
|
||||
} else {
|
||||
@@ -60,7 +61,7 @@ func checkPath(pathObject string) (string, bool) {
|
||||
str := strings.Split(pathObject, ".")
|
||||
pathObject = ""
|
||||
if len(str) == 1 || str[0] != "" {
|
||||
fmt.Println("Path must start with '.'")
|
||||
printError(errors.New("path must start with '.'"))
|
||||
return pathObject, false
|
||||
}
|
||||
for key, value := range str {
|
||||
@@ -78,7 +79,7 @@ func checkPath(pathObject string) (string, bool) {
|
||||
|
||||
func printAnswer(data interface{}) {
|
||||
if answer, err := json.MarshalIndent(data, "", " "); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
} else {
|
||||
service.ColorService.Print(answer)
|
||||
}
|
||||
@@ -86,7 +87,7 @@ func printAnswer(data interface{}) {
|
||||
|
||||
func getModuleConfiguration(moduleName string) (*cfg.Config, []byte) {
|
||||
if moduleName == "" {
|
||||
fmt.Println("Need module name. Use 'info' for get module names")
|
||||
printError(errors.New("need module name. Use 'schema' for get module names"))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -94,18 +95,18 @@ func getModuleConfiguration(moduleName string) (*cfg.Config, []byte) {
|
||||
if err != nil {
|
||||
if errorResponse, ok := err.(http.ErrorResponse); ok {
|
||||
if errorResponse.StatusCode == fasthttp.StatusNotFound {
|
||||
fmt.Printf("Module '%s' not found\n", moduleName)
|
||||
printError(errors.New(fmt.Sprintf("module '%s' not found\n", moduleName)))
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return nil, nil
|
||||
} else {
|
||||
return moduleConfiguration, jsonObject
|
||||
@@ -116,13 +117,13 @@ func createUpdateConfig(stringToChange string, configuration *cfg.Config) {
|
||||
newData := make(map[string]interface{})
|
||||
if stringToChange != "" {
|
||||
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if ok, err := service.UnsafeService.CheckConfigurationSchema(configuration.ModuleId, newData); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
} else if !ok {
|
||||
return
|
||||
@@ -130,8 +131,12 @@ func createUpdateConfig(stringToChange string, configuration *cfg.Config) {
|
||||
|
||||
configuration.Data = newData
|
||||
if resp, err := service.ConfigClient.CreateUpdateConfig(*configuration); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
} else {
|
||||
printAnswer(resp.Data)
|
||||
}
|
||||
}
|
||||
|
||||
func printError(err error) {
|
||||
fmt.Println("ERROR", err)
|
||||
}
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
@@ -20,7 +19,7 @@ type deleteCommand struct{}
|
||||
|
||||
func (d deleteCommand) action(c *cli.Context) {
|
||||
if err := checkFlags(c); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
moduleName := c.Args().First()
|
||||
@@ -40,7 +39,7 @@ func (d deleteCommand) action(c *cli.Context) {
|
||||
createUpdateConfig("", moduleConfiguration)
|
||||
} else {
|
||||
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
} else {
|
||||
createUpdateConfig(stringToChange, moduleConfiguration)
|
||||
|
||||
+4
-3
@@ -2,6 +2,7 @@ package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/tidwall/gjson"
|
||||
@@ -21,7 +22,7 @@ type getCommand struct{}
|
||||
|
||||
func (g getCommand) action(c *cli.Context) {
|
||||
if err := checkFlags(c); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
moduleName := c.Args().First()
|
||||
@@ -47,11 +48,11 @@ func (g getCommand) action(c *cli.Context) {
|
||||
func (g getCommand) checkObject(jsonObject []byte, depth string) {
|
||||
jsonString := gjson.Get(string(jsonObject), depth)
|
||||
if jsonString.Raw == "" {
|
||||
fmt.Printf("Path '%s' not found\n", depth)
|
||||
printError(errors.New(fmt.Sprintf("Path '%s' not found\n", depth)))
|
||||
} else {
|
||||
var data interface{}
|
||||
if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
} else {
|
||||
printAnswer(data)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package command
|
||||
|
||||
const htmlTemplate = `<html>
|
||||
<head>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/json-schema-view-js@2.0.1/dist/bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/json-schema-view-js@2.0.1/dist/style.min.css">
|
||||
<style>
|
||||
.json-schema-view-dark {
|
||||
background: #222;
|
||||
}
|
||||
h3 + div > div {
|
||||
padding: 1em;
|
||||
}
|
||||
pre {
|
||||
background: #333;
|
||||
color: white;
|
||||
padding: 10px;
|
||||
font-size: 1.2em;
|
||||
line-height: 1.3;
|
||||
}
|
||||
/*
|
||||
* Page layout
|
||||
*/
|
||||
body {
|
||||
max-width: 80vw;
|
||||
margin: 30px auto;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
header {
|
||||
overflow: hidden;
|
||||
}
|
||||
header h1 {
|
||||
float: left;
|
||||
}
|
||||
header > div {
|
||||
text-align: right;
|
||||
padding: 10px;
|
||||
}
|
||||
header > div * {
|
||||
vertical-align: middle;
|
||||
}
|
||||
.code-in-gh {
|
||||
background: steelblue;
|
||||
color: white;
|
||||
padding: .5em;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="results"></div>
|
||||
<script>
|
||||
var schema = [
|
||||
{{ . }}
|
||||
];
|
||||
var results = document.querySelector('.results');
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
schema.forEach(function (example) {
|
||||
var title = document.createElement('h3');
|
||||
var formatter = new JSONSchemaView(example.schema, 1, { theme: example.theme });
|
||||
title.innerText = example.title;
|
||||
results.appendChild(title)
|
||||
results.appendChild(formatter.render());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
@@ -0,0 +1,73 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"html/template"
|
||||
"isp-ctl/flag"
|
||||
"isp-ctl/service"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Schema() cli.Command {
|
||||
return cli.Command{
|
||||
Name: "schema",
|
||||
Usage: "get schema configuration by module_name",
|
||||
Action: schema.action,
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrint,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var schema schemaCommand
|
||||
|
||||
type schemaCommand struct{}
|
||||
|
||||
func (s schemaCommand) action(c *cli.Context) {
|
||||
if err := checkFlags(c); err != nil {
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
moduleName := c.Args().First()
|
||||
|
||||
if schemaConfig := s.getSchemaConfig(moduleName); schemaConfig != nil {
|
||||
schema := make(map[string]interface{})
|
||||
schema["title"] = moduleName
|
||||
schema["schema"] = schemaConfig
|
||||
|
||||
switch c.String(flag.OutPrint.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
printAnswer(schema)
|
||||
case flag.OutPrintHtmlValue:
|
||||
s.printHtml(schema)
|
||||
default:
|
||||
printError(errors.New(fmt.Sprintf(
|
||||
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
|
||||
if configuration, _ := getModuleConfiguration(moduleName); configuration == nil {
|
||||
return nil
|
||||
} else if schema, err := service.ConfigClient.GetSchemaByModuleId(configuration.ModuleId); err != nil {
|
||||
printError(err)
|
||||
return nil
|
||||
} else {
|
||||
return schema.Schema
|
||||
}
|
||||
}
|
||||
|
||||
func (s schemaCommand) printHtml(schema map[string]interface{}) {
|
||||
if temp, err := template.New("template").Parse(htmlTemplate); err != nil {
|
||||
printError(err)
|
||||
return
|
||||
} else {
|
||||
if err := temp.ExecuteTemplate(os.Stdout, "template", schema); err != nil {
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -3,6 +3,7 @@ package command
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/tidwall/sjson"
|
||||
@@ -23,7 +24,7 @@ type setCommand struct{}
|
||||
|
||||
func (s setCommand) action(c *cli.Context) {
|
||||
if err := checkFlags(c); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ func (s setCommand) action(c *cli.Context) {
|
||||
}
|
||||
|
||||
if changeObject == "" {
|
||||
fmt.Println("Error. Expected argument")
|
||||
printError(errors.New("expected argument"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -59,7 +60,7 @@ func (s setCommand) action(c *cli.Context) {
|
||||
} else {
|
||||
changeArgument := s.parseObject(changeObject)
|
||||
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
} else {
|
||||
createUpdateConfig(stringToChange, moduleConfiguration)
|
||||
|
||||
+2
-2
@@ -31,11 +31,11 @@ type statusCommand struct{}
|
||||
|
||||
func (statusCommand) action(c *cli.Context) {
|
||||
if err := checkFlags(c); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
return
|
||||
}
|
||||
if arrayOfModules, err := service.ConfigClient.GetAvailableConfigs(); err != nil {
|
||||
fmt.Println(err)
|
||||
printError(err)
|
||||
} else {
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package flag
|
||||
|
||||
import "github.com/codegangsta/cli"
|
||||
|
||||
var (
|
||||
Host = cli.StringFlag{Name: GateHostName, Usage: "overrides gateHost"}
|
||||
Uuid = cli.StringFlag{Name: InstanceUuidName, Usage: "overrides instanceUuid"}
|
||||
Color = cli.BoolFlag{Name: ColorName, Usage: "colorize the json for outputing to screen"}
|
||||
Unsafe = cli.BoolFlag{Name: UnsafeName, Usage: "disable checking schema for set configuration"}
|
||||
)
|
||||
@@ -0,0 +1,25 @@
|
||||
package flag
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
hostName = "gateHost, g"
|
||||
hostUsage = "overrides gateHost"
|
||||
|
||||
uuidName = "instanceUuid, u"
|
||||
uuidUsage = "overrides instanceUuid"
|
||||
|
||||
colorName = "color, c"
|
||||
colorUsage = "colorize the json for outputing to screen"
|
||||
|
||||
unsafeName = "unsafe"
|
||||
unsafeUsage = "disable checking schema for set configuration"
|
||||
|
||||
outPrintName = "o"
|
||||
OutPrintJsonValue = "json"
|
||||
OutPrintHtmlValue = "html"
|
||||
)
|
||||
|
||||
var (
|
||||
outPrintUsage = fmt.Sprintf("out print for schema; %s or %s", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
)
|
||||
@@ -1,8 +0,0 @@
|
||||
package flag
|
||||
|
||||
const (
|
||||
GateHostName = "gateHost, g"
|
||||
InstanceUuidName = "instanceUuid, u"
|
||||
ColorName = "color, c"
|
||||
UnsafeName = "unsafe"
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
package flag
|
||||
|
||||
import "github.com/codegangsta/cli"
|
||||
|
||||
var (
|
||||
//---global---
|
||||
Host = cli.StringFlag{Name: hostName, Usage: hostUsage}
|
||||
Uuid = cli.StringFlag{Name: uuidName, Usage: uuidUsage}
|
||||
Color = cli.BoolFlag{Name: colorName, Usage: colorUsage}
|
||||
Unsafe = cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
|
||||
//---local---
|
||||
OutPrint = cli.StringFlag{Name: outPrintName, Usage: outPrintUsage, Value: OutPrintJsonValue}
|
||||
)
|
||||
@@ -23,7 +23,8 @@ func initCommands() {
|
||||
` ispctl [flag...] status
|
||||
ispctl [flag...] get module_name property_path
|
||||
ispctl [flag...] set module_name property_path [new_object]
|
||||
ispctl [flag...] delete module_name property_path`
|
||||
ispctl [flag...] delete module_name property_path
|
||||
ispctl [flag...] schema module_name [local_flag]`
|
||||
|
||||
app.Version = version
|
||||
|
||||
@@ -39,6 +40,7 @@ func initCommands() {
|
||||
command.Get(),
|
||||
command.Set(),
|
||||
command.Delete(),
|
||||
command.Schema(),
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
|
||||
Reference in new issue
Block a user