group verb: group help before the refusals, and lists role (Astra r1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+24
−8
system_group.go+10 −5system_group_test.go+14 −3
diff --git a/system_group.go b/system_group.go| index 0e21d641c..74a68efae 100644 |
| --- a/system_group.go |
| +++ b/system_group.go |
| @@ -111,8 +111,7 @@ func groupProbeHelp(args []string) int { |
| } |
| // systemGroupFallback is bare `carlos system group`, its -h, and a verb it |
| -// does not have: the group's own help, after the same root and box |
| -// refusals as every verb. |
| +// does not have: the group's own help. |
| func systemGroupFallback(args, _ []string) { os.Exit(runSystemGroup("", args)) } |
| // groupVerbsHelp is the verb list groupHelp prints, in the order an |
| @@ -132,6 +131,9 @@ func groupHelp(args []string) int { |
| for _, v := range groupVerbsHelp { |
| fmt.Fprintf(&b, " %-13s %s\n", v.verb, grouproll.Text(v.key)) |
| } |
| + // role goes through the console, not the group config; its line is |
| + // the one carlos system's own help prints. |
| + b.WriteString(" role <region> <default|legacy>\n") |
| if len(args) == 1 && (args[0] == "-h" || args[0] == "-help" || args[0] == "--help") { |
| fmt.Fprint(groupEnv.stdout, b.String()) |
| return 0 |
| @@ -311,6 +313,12 @@ func attendedBy(flagValue string) string { |
| // files from the environment; load the config; isolate the environment |
| // for its profile (before any goroutine starts); then the verb. |
| func runSystemGroup(verb string, args []string) int { |
| + // The group's help reads nothing and changes nothing, so it prints |
| + // anywhere, as root and on a box too: the CLI golden must not depend |
| + // on the machine it runs on (Astra r1 P1). |
| + if verb == "" { |
| + return groupHelp(args) |
| + } |
| if !groupSupported { |
| return groupRefused(grouproll.Refusal{Key: "windows"}) |
| } |
| @@ -323,9 +331,6 @@ func runSystemGroup(verb string, args []string) int { |
| if verb == "probe" { |
| return groupProbeHelp(args) |
| } |
| - if verb == "" { |
| - return groupHelp(args) |
| - } |
| f, rc, ok := parseGroupFlags(verb, args) |
| if !ok { |
| return rc |
diff --git a/system_group_test.go b/system_group_test.go| index 4a0fce9d3..718b97fed 100644 |
| --- a/system_group_test.go |
| +++ b/system_group_test.go |
| @@ -539,7 +539,7 @@ func TestCLIProbeLeaves(t *testing.T) { |
| } |
| // Bare carlos system group, its -h and an unknown verb print the group's |
| -// help (every verb with its line), after the root refusal. |
| +// help (every verb with its line), on any machine. |
| func TestCLIGroupHelp(t *testing.T) { |
| h := newGroupHarness(t) |
| if rc := h.run("", "-h"); rc != 0 || h.stderr.Len() != 0 { |
| @@ -560,10 +560,21 @@ func TestCLIGroupHelp(t *testing.T) { |
| t.Errorf("%v: rc %d stderr %q", args, rc, h.stderr.String()) |
| } |
| } |
| + if !strings.Contains(out, " role <region> <default|legacy>\n") { |
| + t.Errorf("-h lacks role: %q", out) |
| + } |
| + // Every registered child is in the help. |
| + for _, c := range systemGroupCommand().Children { |
| + if !strings.Contains(out, " "+c.Name+" ") { |
| + t.Errorf("-h lacks registered %s", c.Name) |
| + } |
| + } |
| + // Help reads and changes nothing, so it prints as root too: the CLI |
| + // golden does not depend on the machine. |
| h = newGroupHarness(t) |
| groupEnv.geteuid = func() int { return 0 } |
| - if rc := h.run("", "-h"); rc != 1 || h.stderr.String() != h.refused("root_refused") { |
| - t.Fatalf("as root: rc %d stderr %q", rc, h.stderr.String()) |
| + if rc := h.run("", "-h"); rc != 0 || h.stdout.String() != out { |
| + t.Fatalf("as root: rc %d stdout %q stderr %q", rc, h.stdout.String(), h.stderr.String()) |
| } |
| } |