Skip to content

Commit 36fb9f5

Browse files
authored
fix: fix empty command name (filebrowser#1106)
1 parent ad99bf1 commit 36fb9f5

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

cmd/config_init.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"strings"
65

76
"github.com/spf13/cobra"
87

@@ -32,7 +31,7 @@ override the options.`,
3231
s := &settings.Settings{
3332
Key: generateKey(),
3433
Signup: mustGetBool(flags, "signup"),
35-
Shell: strings.Split(strings.TrimSpace(mustGetString(flags, "shell")), " "),
34+
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
3635
AuthMethod: authMethod,
3736
Defaults: defaults,
3837
Branding: settings.Branding{

cmd/config_set.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cmd
22

33
import (
4-
"strings"
5-
64
"github.com/spf13/cobra"
75
"github.com/spf13/pflag"
86
)
@@ -50,7 +48,7 @@ you want to change. Other options will remain unchanged.`,
5048
case "auth.method":
5149
hasAuth = true
5250
case "shell":
53-
set.Shell = strings.Split(strings.TrimSpace(mustGetString(flags, flag.Name)), " ")
51+
set.Shell = convertCmdStrToCmdArray(mustGetString(flags, flag.Name))
5452
case "branding.name":
5553
set.Branding.Name = mustGetString(flags, flag.Name)
5654
case "branding.disableExternal":

cmd/utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"path/filepath"
10+
"strings"
1011

1112
"github.com/asdine/storm"
1213
"github.com/spf13/cobra"
@@ -178,3 +179,15 @@ func cleanUpMapValue(v interface{}) interface{} {
178179
return v
179180
}
180181
}
182+
183+
// convertCmdStrToCmdArray checks if cmd string is blank (whitespace included)
184+
// then returns empty string array, else returns the splitted word array of cmd.
185+
// This is to ensure the result will never be []string{""}
186+
func convertCmdStrToCmdArray(cmd string) []string {
187+
var cmdArray []string
188+
trimmedCmdStr := strings.TrimSpace(cmd)
189+
if trimmedCmdStr != "" {
190+
cmdArray = strings.Split(trimmedCmdStr, " ")
191+
}
192+
return cmdArray
193+
}

0 commit comments

Comments
 (0)