diff --git a/bash/autocomplete.go b/bash/autocomplete.go index 17d85fc..2e01ad5 100644 --- a/bash/autocomplete.go +++ b/bash/autocomplete.go @@ -2,11 +2,13 @@ package bash import ( "fmt" + "github.com/urfave/cli/v2" - "github.com/txix-open/bellows" "ispctl/command/flag" "ispctl/service" + + "github.com/txix-open/bellows" ) const ( @@ -33,7 +35,8 @@ func Get(first bashArg, second bashArg) *bashCommand { } func (c bashCommand) Complete(ctx *cli.Context) { - if err := flag.CheckGlobal(ctx); err != nil { + err := flag.ApplyGlobalFlags(ctx) + if err != nil { return } diff --git a/command/delete.go b/command/delete.go index f9a4024..70d59ce 100644 --- a/command/delete.go +++ b/command/delete.go @@ -3,19 +3,20 @@ package command import ( "encoding/json" - "github.com/tidwall/sjson" - "github.com/urfave/cli/v2" "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" "ispctl/service" + + "github.com/tidwall/sjson" + "github.com/urfave/cli/v2" ) func Delete() *cli.Command { return &cli.Command{ Name: "delete", Usage: "delete configuration by module_name", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: deleteComm.action, BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, } diff --git a/command/flag/structure.go b/command/flag/structure.go index 12a6f27..5cc0cb0 100644 --- a/command/flag/structure.go +++ b/command/flag/structure.go @@ -25,10 +25,8 @@ var ( SetVariableSecretType = &cli.BoolFlag{Name: secretVariableName, Usage: secretVariableUsage} ) -func CheckGlobal(c *cli.Context) error { - var ( - host string - ) +func ApplyGlobalFlags(c *cli.Context) error { + var host string service.Config.UnsafeEnable = c.Bool(Unsafe.Name) host = c.String(Host.Name) diff --git a/command/get.go b/command/get.go index b49eee8..c71e903 100644 --- a/command/get.go +++ b/command/get.go @@ -3,18 +3,19 @@ package command import ( "encoding/json" - "github.com/urfave/cli/v2" "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" "ispctl/service" + + "github.com/urfave/cli/v2" ) func Get() *cli.Command { return &cli.Command{ Name: "get", Usage: "get configuration by module_name", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: get.action, BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, } @@ -25,7 +26,7 @@ var get getCommand type getCommand struct{} func (g getCommand) action(ctx *cli.Context) error { - if err := flag.CheckGlobal(ctx); err != nil { + if err := flag.ApplyGlobalFlags(ctx); err != nil { return err } moduleName := ctx.Args().First() diff --git a/command/merge.go b/command/merge.go index 866f7aa..13fbe85 100644 --- a/command/merge.go +++ b/command/merge.go @@ -4,12 +4,13 @@ import ( "encoding/json" "os" - "github.com/pkg/errors" - "github.com/urfave/cli/v2" "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" "ispctl/service" + + "github.com/pkg/errors" + "github.com/urfave/cli/v2" ) func Merge() *cli.Command { @@ -17,7 +18,7 @@ func Merge() *cli.Command { Name: "merge", Usage: "merge actual config with config from stdin", BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete, - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: func(context *cli.Context) error { moduleName := context.Args().First() config, err := service.Config.GetConfigurationByModuleName(moduleName) diff --git a/command/schema.go b/command/schema.go index 698313e..e1c4720 100644 --- a/command/schema.go +++ b/command/schema.go @@ -4,20 +4,21 @@ import ( "html/template" "os" - "github.com/pkg/errors" - "github.com/urfave/cli/v2" "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" "ispctl/service" "ispctl/tmpl" + + "github.com/pkg/errors" + "github.com/urfave/cli/v2" ) func Schema() *cli.Command { return &cli.Command{ Name: "schema", Usage: "get schema configuration by module_name", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: schema.action, Flags: []cli.Flag{ flag.OutPrintSchema, diff --git a/command/set.go b/command/set.go index adf57dc..7fb92ea 100644 --- a/command/set.go +++ b/command/set.go @@ -3,19 +3,20 @@ package command import ( "encoding/json" - "github.com/tidwall/sjson" - "github.com/urfave/cli/v2" "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" "ispctl/service" + + "github.com/tidwall/sjson" + "github.com/urfave/cli/v2" ) func Set() *cli.Command { return &cli.Command{ Name: "set", Usage: "set configuration by module_name", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: set.action, BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete, } diff --git a/command/status.go b/command/status.go index 9fb5dee..0294fc2 100644 --- a/command/status.go +++ b/command/status.go @@ -5,11 +5,12 @@ import ( "os" "strings" - "github.com/olekukonko/tablewriter" - "github.com/urfave/cli/v2" "ispctl/command/flag" "ispctl/command/utils" "ispctl/service" + + "github.com/olekukonko/tablewriter" + "github.com/urfave/cli/v2" ) const ( @@ -25,7 +26,7 @@ func Status() *cli.Command { return &cli.Command{ Name: "status", Usage: "get available configs", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: status.action, Flags: []cli.Flag{ flag.OutPrintStatus, diff --git a/command/vars.go b/command/vars.go index 9262906..b7e5336 100644 --- a/command/vars.go +++ b/command/vars.go @@ -3,8 +3,6 @@ package command import ( "encoding/csv" "fmt" - "github.com/olekukonko/tablewriter" - "github.com/urfave/cli/v2" "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" @@ -12,6 +10,9 @@ import ( "ispctl/service" "os" "strings" + + "github.com/olekukonko/tablewriter" + "github.com/urfave/cli/v2" ) func VariablesCommands() *cli.Command { @@ -22,20 +23,20 @@ func VariablesCommands() *cli.Command { { Name: "get", Usage: "vars get ", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: varsComm.getByName, BashComplete: bash.Get(bash.VariableName, bash.Empty).Complete, }, { Name: "list", Usage: "list all variables", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: varsComm.list, }, { Name: "set", Usage: "vars set ", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: varsComm.set, Flags: []cli.Flag{ flag.SetVariableSecretType, @@ -45,14 +46,14 @@ func VariablesCommands() *cli.Command { { Name: "delete", Usage: "vars delete ", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: varsComm.delete, BashComplete: bash.Get(bash.VariableName, bash.Empty).Complete, }, { Name: "upload", Usage: "vars upload ", - Before: flag.CheckGlobal, + Before: flag.ApplyGlobalFlags, Action: varsComm.upload, }, },