MSP-5014 Remove flag package

This commit is contained in:
Синельник Тимур Романович committed 2025-03-24 11:30:39 +03:00
1 parent c267b1ae6e
commit 533f2da29a
7 files changed
+46 -63

No files matched your search

-23
View File
@@ -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"
)
-22
View File
@@ -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}
)
+23
View File
@@ -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
View File
@@ -5,7 +5,6 @@ import (
"os" "os"
"ispctl/bash" "ispctl/bash"
"ispctl/command/flag"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/model" "ispctl/model"
"ispctl/tmpl" "ispctl/tmpl"
@@ -38,7 +37,7 @@ func (c Schema) Command() *cli.Command {
Usage: "get schema configuration by module_name", Usage: "get schema configuration by module_name",
Action: c.action, Action: c.action,
Flags: []cli.Flag{ Flags: []cli.Flag{
flag.OutPrintSchema, &cli.StringFlag{Name: OutPrintFlagName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue},
}, },
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.Empty), 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 := make(map[string]any)
schema["title"] = moduleName schema["title"] = moduleName
schema["schema"] = schemaConfig schema["schema"] = schemaConfig
switch ctx.String(flag.OutPrintSchema.Name) { switch ctx.String(OutPrintFlagName) {
case flag.OutPrintJsonValue: case OutPrintJsonValue:
utils.PrintAnswer(schema) utils.PrintAnswer(schema)
case flag.OutPrintHtmlValue: case OutPrintHtmlValue:
return c.printHtml(schema) return c.printHtml(schema)
default: 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 return nil
} }
+3 -4
View File
@@ -5,7 +5,6 @@ import (
"os" "os"
"strings" "strings"
"ispctl/command/flag"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/model" "ispctl/model"
@@ -40,7 +39,7 @@ func (c Status) Command() *cli.Command {
Usage: "get available configs", Usage: "get available configs",
Action: c.action, Action: c.action,
Flags: []cli.Flag{ 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 { if err != nil {
return err return err
} }
switch ctx.String(flag.OutPrintStatus.Name) { switch ctx.String(OutPrintFlagName) {
case flag.OutPrintJsonValue: case OutPrintJsonValue:
utils.PrintAnswer(arrayOfModules) utils.PrintAnswer(arrayOfModules)
default: default:
table := tablewriter.NewWriter(os.Stdout) table := tablewriter.NewWriter(os.Stdout)
+2 -3
View File
@@ -4,7 +4,6 @@ import (
"encoding/csv" "encoding/csv"
"fmt" "fmt"
"ispctl/bash" "ispctl/bash"
"ispctl/command/flag"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/model" "ispctl/model"
"os" "os"
@@ -54,7 +53,7 @@ func (c Variables) Command() *cli.Command {
Usage: "vars set <name> <value>", Usage: "vars set <name> <value>",
Action: c.set, Action: c.set,
Flags: []cli.Flag{ Flags: []cli.Flag{
flag.SetVariableSecretType, &cli.BoolFlag{Name: SecretFlagName, Usage: secretVariableFlagUsage},
}, },
BashComplete: c.autoComplete.Complete(bash.VariableName, bash.Empty), 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) variableName := ctx.Args().Get(0)
variableValue := ctx.Args().Get(1) variableValue := ctx.Args().Get(1)
variableType := model.TextVariableType variableType := model.TextVariableType
if ctx.Bool(flag.SetVariableSecretType.Name) { if ctx.Bool(SecretFlagName) {
variableType = model.SecretVariableType variableType = model.SecretVariableType
} }
return c.service.UpsertVariables([]model.UpsertVariableRequest{{ return c.service.UpsertVariables([]model.UpsertVariableRequest{{
+13 -5
View File
@@ -8,7 +8,6 @@ import (
"ispctl/bash" "ispctl/bash"
"ispctl/command" "ispctl/command"
"ispctl/command/flag"
"ispctl/repository" "ispctl/repository"
"ispctl/service" "ispctl/service"
@@ -27,8 +26,17 @@ func initCommands() {
app.Version = version app.Version = version
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
flag.Host, &cli.StringFlag{
flag.Unsafe, 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 app.EnableBashCompletion = true
@@ -58,9 +66,9 @@ func initCommands() {
} }
func configServiceFromGlobalFlags(ctx *cli.Context) (service.Config, error) { 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) host = strings.Replace(host, "'", "", -1)
configCli, err := repository.NewGrpcClientWithHost(host) configCli, err := repository.NewGrpcClientWithHost(host)