From d0226dabdb8ba0bb71f5c0ec3b6a3f2ba45a54f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=A9re=C5=A1?= Date: Mon, 23 Oct 2023 01:15:06 -0700 Subject: [PATCH] replace occurencies of agentctl with swctl for config --help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Béreš --- cmd/swctl/app/cmd_config.go | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/cmd/swctl/app/cmd_config.go b/cmd/swctl/app/cmd_config.go index 96a79df..e713803 100644 --- a/cmd/swctl/app/cmd_config.go +++ b/cmd/swctl/app/cmd_config.go @@ -43,20 +43,12 @@ func NewConfigCmd(cli Cli) *cobra.Command { return cmd } -type temporaryFlag struct { - // full name flag - key string - // full line - value string -} - func runConfigCmd(cli Cli, opts ConfigCmdOptions, cmd *cobra.Command) error { - var ParsedFlags []temporaryFlag args := opts.Args if slices.Contains(args, "--help") || slices.Contains(args, "-h") { // add Local flags to stdout of agentctl - stdout, stderr, shouldReturn, returnValue := mergeHelpers(cmd, ParsedFlags, cli, args) + stdout, stderr, shouldReturn, returnValue := mergeHelpers(cmd, cli, args) if shouldReturn { return returnValue } @@ -87,29 +79,15 @@ func runConfigCmd(cli Cli, opts ConfigCmdOptions, cmd *cobra.Command) error { return nil } -func mergeHelpers(cmd *cobra.Command, ParsedFlags []temporaryFlag, cli Cli, args []string) (string, string, bool, error) { +func mergeHelpers(cmd *cobra.Command, cli Cli, args []string) (string, string, bool, error) { flags := cmd.LocalFlags() bufb := flags.FlagUsages() - for _, v := range strings.Split(bufb, "\n") { - var flag temporaryFlag - ls := strings.ReplaceAll(v, ",", " ") - tokenized := strings.Fields(ls) - for _, token := range tokenized { - if strings.Contains(token, "--") { - flag.key = token - flag.value = v - break - } - } - ParsedFlags = append(ParsedFlags, flag) - } - _ = ParsedFlags - stdout, stderr, err := cli.Exec("agentctl config", args, false) if err != nil { return "", "", true, err } + stdout = strings.ReplaceAll(stdout, "agentctl", "swctl") globalsIndex := strings.Index(stdout, "GLOBALS:") if globalsIndex != -1 {