MSP-5014 CheckGlobal to ApplyGlobalFlags
This commit is contained in:
1 parent
ff2922cf1e
commit
0005f1ac0c
9 files changed
+39
-31
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
+4
-3
@@ -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()
|
||||
|
||||
+4
-3
@@ -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)
|
||||
|
||||
+4
-3
@@ -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,
|
||||
|
||||
+4
-3
@@ -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,
|
||||
}
|
||||
|
||||
+4
-3
@@ -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,
|
||||
|
||||
+8
-7
@@ -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 <name>",
|
||||
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 <name> <value>",
|
||||
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 <name>",
|
||||
Before: flag.CheckGlobal,
|
||||
Before: flag.ApplyGlobalFlags,
|
||||
Action: varsComm.delete,
|
||||
BashComplete: bash.Get(bash.VariableName, bash.Empty).Complete,
|
||||
},
|
||||
{
|
||||
Name: "upload",
|
||||
Usage: "vars upload <filepath>",
|
||||
Before: flag.CheckGlobal,
|
||||
Before: flag.ApplyGlobalFlags,
|
||||
Action: varsComm.upload,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user