MSP-5014 Remove flag package
This commit is contained in:
1 parent
c267b1ae6e
commit
533f2da29a
7 files changed
+46
-63
No files matched your search
@@ -1,23 +0,0 @@
|
||||
package flag
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
hostName = "gateHost"
|
||||
hostUsage = "isp-config-service address"
|
||||
|
||||
unsafeName = "unsafe"
|
||||
unsafeUsage = "disable checking schema for set configuration"
|
||||
|
||||
outPrintName = "o"
|
||||
OutPrintJsonValue = "json"
|
||||
OutPrintHtmlValue = "html"
|
||||
|
||||
secretVariableName = "secret"
|
||||
)
|
||||
|
||||
var (
|
||||
outPrintStatusUsage = fmt.Sprintf("out print for status; %s", OutPrintJsonValue)
|
||||
outPrintSchemaUsage = fmt.Sprintf("out print for schema; %s or %s", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
secretVariableUsage = "set variable as secret"
|
||||
)
|
||||
@@ -1,22 +0,0 @@
|
||||
package flag
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
//---global---
|
||||
Host = &cli.StringFlag{
|
||||
Name: hostName,
|
||||
Usage: hostUsage,
|
||||
Value: "127.0.0.1:9002",
|
||||
Required: false,
|
||||
Aliases: []string{"g", "configAddr"},
|
||||
}
|
||||
Unsafe = &cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
|
||||
//---local---
|
||||
OutPrintStatus = &cli.StringFlag{Name: outPrintName, Usage: outPrintStatusUsage}
|
||||
OutPrintSchema = &cli.StringFlag{Name: outPrintName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue}
|
||||
|
||||
SetVariableSecretType = &cli.BoolFlag{Name: secretVariableName, Usage: secretVariableUsage}
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
package command
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
HostFlagName = "gateHost"
|
||||
HostFlagUsage = "isp-config-service address"
|
||||
|
||||
UnsafeFlagName = "unsafe"
|
||||
UnsafeFlagUsage = "disable checking schema for set configuration"
|
||||
|
||||
OutPrintFlagName = "o"
|
||||
OutPrintJsonValue = "json"
|
||||
OutPrintHtmlValue = "html"
|
||||
|
||||
SecretFlagName = "secret"
|
||||
secretVariableFlagUsage = "set variable as secret"
|
||||
)
|
||||
|
||||
var (
|
||||
outPrintStatusUsage = fmt.Sprintf("out print for status; %s", OutPrintJsonValue)
|
||||
outPrintSchemaUsage = fmt.Sprintf("out print for schema; %s or %s", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
)
|
||||
+5
-6
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
|
||||
"ispctl/bash"
|
||||
"ispctl/command/flag"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/model"
|
||||
"ispctl/tmpl"
|
||||
@@ -38,7 +37,7 @@ func (c Schema) Command() *cli.Command {
|
||||
Usage: "get schema configuration by module_name",
|
||||
Action: c.action,
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrintSchema,
|
||||
&cli.StringFlag{Name: OutPrintFlagName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue},
|
||||
},
|
||||
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.Empty),
|
||||
}
|
||||
@@ -54,13 +53,13 @@ func (c Schema) action(ctx *cli.Context) error {
|
||||
schema := make(map[string]any)
|
||||
schema["title"] = moduleName
|
||||
schema["schema"] = schemaConfig
|
||||
switch ctx.String(flag.OutPrintSchema.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
switch ctx.String(OutPrintFlagName) {
|
||||
case OutPrintJsonValue:
|
||||
utils.PrintAnswer(schema)
|
||||
case flag.OutPrintHtmlValue:
|
||||
case OutPrintHtmlValue:
|
||||
return c.printHtml(schema)
|
||||
default:
|
||||
return errors.Errorf("invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)
|
||||
return errors.Errorf("invalid flag value, expected [%s] or [%s]", OutPrintJsonValue, OutPrintHtmlValue)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+3
-4
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"ispctl/command/flag"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/model"
|
||||
|
||||
@@ -40,7 +39,7 @@ func (c Status) Command() *cli.Command {
|
||||
Usage: "get available configs",
|
||||
Action: c.action,
|
||||
Flags: []cli.Flag{
|
||||
flag.OutPrintStatus,
|
||||
&cli.StringFlag{Name: OutPrintFlagName, Usage: outPrintStatusUsage},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -50,8 +49,8 @@ func (c Status) action(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch ctx.String(flag.OutPrintStatus.Name) {
|
||||
case flag.OutPrintJsonValue:
|
||||
switch ctx.String(OutPrintFlagName) {
|
||||
case OutPrintJsonValue:
|
||||
utils.PrintAnswer(arrayOfModules)
|
||||
default:
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
|
||||
+2
-3
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"ispctl/bash"
|
||||
"ispctl/command/flag"
|
||||
"ispctl/command/utils"
|
||||
"ispctl/model"
|
||||
"os"
|
||||
@@ -54,7 +53,7 @@ func (c Variables) Command() *cli.Command {
|
||||
Usage: "vars set <name> <value>",
|
||||
Action: c.set,
|
||||
Flags: []cli.Flag{
|
||||
flag.SetVariableSecretType,
|
||||
&cli.BoolFlag{Name: SecretFlagName, Usage: secretVariableFlagUsage},
|
||||
},
|
||||
BashComplete: c.autoComplete.Complete(bash.VariableName, bash.Empty),
|
||||
},
|
||||
@@ -107,7 +106,7 @@ func (c Variables) set(ctx *cli.Context) error {
|
||||
variableName := ctx.Args().Get(0)
|
||||
variableValue := ctx.Args().Get(1)
|
||||
variableType := model.TextVariableType
|
||||
if ctx.Bool(flag.SetVariableSecretType.Name) {
|
||||
if ctx.Bool(SecretFlagName) {
|
||||
variableType = model.SecretVariableType
|
||||
}
|
||||
return c.service.UpsertVariables([]model.UpsertVariableRequest{{
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"ispctl/bash"
|
||||
"ispctl/command"
|
||||
"ispctl/command/flag"
|
||||
"ispctl/repository"
|
||||
"ispctl/service"
|
||||
|
||||
@@ -27,8 +26,17 @@ func initCommands() {
|
||||
|
||||
app.Version = version
|
||||
app.Flags = []cli.Flag{
|
||||
flag.Host,
|
||||
flag.Unsafe,
|
||||
&cli.StringFlag{
|
||||
Name: command.HostFlagName,
|
||||
Usage: command.HostFlagUsage,
|
||||
Value: "127.0.0.1:9002",
|
||||
Required: false,
|
||||
Aliases: []string{"g", "configAddr"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: command.UnsafeFlagName,
|
||||
Usage: command.UnsafeFlagUsage,
|
||||
},
|
||||
}
|
||||
app.EnableBashCompletion = true
|
||||
|
||||
@@ -58,9 +66,9 @@ func initCommands() {
|
||||
}
|
||||
|
||||
func configServiceFromGlobalFlags(ctx *cli.Context) (service.Config, error) {
|
||||
enableUnsafe := ctx.Bool(flag.Unsafe.Name)
|
||||
enableUnsafe := ctx.Bool(command.UnsafeFlagName)
|
||||
|
||||
host := ctx.String(flag.Host.Name)
|
||||
host := ctx.String(command.HostFlagName)
|
||||
host = strings.Replace(host, "'", "", -1)
|
||||
|
||||
configCli, err := repository.NewGrpcClientWithHost(host)
|
||||
|
||||
Reference in new issue
Block a user