From 533f2da29aa95bac0dba88f39d28f174a7b32760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 21 Mar 2025 18:22:54 +0300 Subject: [PATCH] MSP-5014 Remove flag package --- command/flag/description.go | 23 ----------------------- command/flag/structure.go | 22 ---------------------- command/flags.go | 23 +++++++++++++++++++++++ command/schema.go | 11 +++++------ command/status.go | 7 +++---- command/vars.go | 5 ++--- main.go | 18 +++++++++++++----- 7 files changed, 46 insertions(+), 63 deletions(-) delete mode 100644 command/flag/description.go delete mode 100644 command/flag/structure.go create mode 100644 command/flags.go diff --git a/command/flag/description.go b/command/flag/description.go deleted file mode 100644 index 2b96052..0000000 --- a/command/flag/description.go +++ /dev/null @@ -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" -) diff --git a/command/flag/structure.go b/command/flag/structure.go deleted file mode 100644 index b5fd06b..0000000 --- a/command/flag/structure.go +++ /dev/null @@ -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} -) diff --git a/command/flags.go b/command/flags.go new file mode 100644 index 0000000..4ef9a0d --- /dev/null +++ b/command/flags.go @@ -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) +) diff --git a/command/schema.go b/command/schema.go index 4df2b20..92def9e 100644 --- a/command/schema.go +++ b/command/schema.go @@ -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 } diff --git a/command/status.go b/command/status.go index 7f3737b..1b390e1 100644 --- a/command/status.go +++ b/command/status.go @@ -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) diff --git a/command/vars.go b/command/vars.go index 00fb40f..bb15422 100644 --- a/command/vars.go +++ b/command/vars.go @@ -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 ", 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{{ diff --git a/main.go b/main.go index 400c673..010d318 100644 --- a/main.go +++ b/main.go @@ -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)