Skip to content

Commit fa25a78

Browse files
committed
fix(cmd): pre-scan --home after subcommands
1 parent 643ba6c commit fa25a78

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

internal/cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ func preScanHomeArg(args []string) (string, bool) {
297297
}
298298
continue
299299
}
300-
return "", false
301300
}
302301
return "", false
303302
}

internal/cmd/root_more_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ func TestRootHomeFlagOverridesHelpDescription(t *testing.T) {
112112
assertPathUnderRoot(t, path, home, "config", "config.json")
113113
}
114114

115+
func TestRootHomeFlagAppliesBeforeSubcommandHelp(t *testing.T) {
116+
setTestConfigHome(t)
117+
118+
err := Execute([]string{"config", "--home", "relative", "--help"})
119+
if err == nil || !strings.Contains(err.Error(), "--home") {
120+
t.Fatalf("expected --home error, got %v", err)
121+
}
122+
}
123+
115124
func helpConfigPath(out string) string {
116125
for _, line := range strings.Split(out, "\n") {
117126
line = strings.TrimSpace(line)
@@ -161,6 +170,11 @@ func TestRootHomePreScanSkipsGlobalFlagValues(t *testing.T) {
161170
if !ok || home != "/tmp/gog" {
162171
t.Fatalf("home=%q ok=%t, want /tmp/gog true", home, ok)
163172
}
173+
174+
home, ok = preScanHomeArg([]string{"config", "--home", "/tmp/gog", "--help"})
175+
if !ok || home != "/tmp/gog" {
176+
t.Fatalf("home=%q ok=%t, want /tmp/gog true", home, ok)
177+
}
164178
}
165179

166180
func TestRootHomeFlagRejectsRelativePath(t *testing.T) {

0 commit comments

Comments
 (0)