Skip to content

Commit c4b0e38

Browse files
Use mq identity in subcommand help
Co-authored-by: Andrew <andrewxhill@gmail.com>
1 parent fa68983 commit c4b0e38

13 files changed

Lines changed: 70 additions & 52 deletions

File tree

internal/app/app_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,14 +944,17 @@ func TestLogsHelpUsesLogsCommandName(t *testing.T) {
944944
func TestSubmitHelpMentionsAgentTurboPath(t *testing.T) {
945945
var stdout bytes.Buffer
946946
var stderr bytes.Buffer
947-
err := runCLI([]string{"submit", "--help"}, &stdout, &stderr)
947+
err := runCLIWithName("mq", []string{"submit", "--help"}, &stdout, &stderr)
948948
if err == nil {
949949
t.Fatalf("expected help error for submit command")
950950
}
951951
output := stderr.String()
952952
if !strings.Contains(output, "mq submit --wait --timeout 15m --json") {
953953
t.Fatalf("expected submit help to mention wait json path, got %q", output)
954954
}
955+
if !strings.Contains(output, "Usage:\n mq submit [flags]") {
956+
t.Fatalf("expected submit help to use mq identity, got %q", output)
957+
}
955958
}
956959

957960
func TestWatchJSONEmitsSnapshots(t *testing.T) {

internal/app/cli.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"strings"
1010
)
1111

12+
var activeCLIProgramName = "mainline"
13+
1214
var cliCommands = []string{
1315
"land",
1416
"submit",
@@ -44,6 +46,12 @@ func runCLI(args []string, stdout io.Writer, stderr io.Writer) error {
4446
}
4547

4648
func runCLIWithName(programName string, args []string, stdout io.Writer, stderr io.Writer) error {
49+
previousProgramName := activeCLIProgramName
50+
activeCLIProgramName = programName
51+
defer func() {
52+
activeCLIProgramName = previousProgramName
53+
}()
54+
4755
fs := flag.NewFlagSet(programName, flag.ContinueOnError)
4856
fs.SetOutput(stderr)
4957

@@ -184,3 +192,10 @@ func setFlagUsage(fs *flag.FlagSet, text string) {
184192
fs.PrintDefaults()
185193
}
186194
}
195+
196+
func currentCLIProgramName() string {
197+
if activeCLIProgramName == "" {
198+
return "mainline"
199+
}
200+
return activeCLIProgramName
201+
}

internal/app/completion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
)
99

1010
func runCompletion(args []string, stdout io.Writer, stderr io.Writer) error {
11-
fs := flag.NewFlagSet("mainline completion", flag.ContinueOnError)
11+
fs := flag.NewFlagSet(currentCLIProgramName()+" completion", flag.ContinueOnError)
1212
fs.SetOutput(stderr)
13-
setFlagUsage(fs, `Usage:
14-
mainline completion [--json] [bash|zsh|fish]
13+
setFlagUsage(fs, fmt.Sprintf(`Usage:
14+
%s completion [--json] [bash|zsh|fish]
1515
1616
Emit a shell completion script for mainline and mq.
1717
@@ -20,7 +20,7 @@ Examples:
2020
mq --json completion bash
2121
2222
Flags:
23-
`)
23+
`, currentCLIProgramName()))
2424
var asJSON bool
2525
fs.BoolVar(&asJSON, "json", false, "output json")
2626
if err := fs.Parse(args); err != nil {

internal/app/confidence.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ type certificationRepoEvidence struct {
7777
}
7878

7979
func runConfidence(args []string, stdout io.Writer, stderr io.Writer) error {
80-
fs := flag.NewFlagSet("mainline confidence", flag.ContinueOnError)
80+
fs := flag.NewFlagSet(currentCLIProgramName()+" confidence", flag.ContinueOnError)
8181
fs.SetOutput(stderr)
82-
setFlagUsage(fs, `Usage:
83-
mainline confidence [flags]
82+
setFlagUsage(fs, fmt.Sprintf(`Usage:
83+
%s confidence [flags]
8484
8585
Summarize live repo health, evidence files, and promotion gates for the current
8686
build.
@@ -90,7 +90,7 @@ Examples:
9090
mq confidence --soak-summary artifacts/soak/latest/summary.json --json
9191
9292
Flags:
93-
`)
93+
`, currentCLIProgramName()))
9494

9595
var repoPath string
9696
var asJSON bool

internal/app/config_edit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
)
1616

1717
func runConfigEdit(args []string, stdout io.Writer, stderr io.Writer) error {
18-
fs := flag.NewFlagSet("mainline config edit", flag.ContinueOnError)
18+
fs := flag.NewFlagSet(currentCLIProgramName()+" config edit", flag.ContinueOnError)
1919
fs.SetOutput(stderr)
20-
setFlagUsage(fs, `Usage:
21-
mainline config edit [flags]
20+
setFlagUsage(fs, fmt.Sprintf(`Usage:
21+
%s config edit [flags]
2222
2323
Open the shared repo config, even when invoked from a linked worktree.
2424
@@ -27,7 +27,7 @@ Examples:
2727
mq config edit --print-path
2828
2929
Flags:
30-
`)
30+
`, currentCLIProgramName()))
3131

3232
var repoPath string
3333
var editor string

internal/app/controls.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func runCancel(args []string, stdout io.Writer, stderr io.Writer) error {
1919
}
2020

2121
func runControlAction(action string, args []string, stdout io.Writer, stderr io.Writer) error {
22-
fs := flag.NewFlagSet("mainline "+action, flag.ContinueOnError)
22+
fs := flag.NewFlagSet(currentCLIProgramName()+" "+action, flag.ContinueOnError)
2323
fs.SetOutput(stderr)
2424
setFlagUsage(fs, fmt.Sprintf(`Usage:
25-
mainline %s [flags]
25+
%s %s [flags]
2626
2727
Operate on exactly one queue item.
2828
@@ -31,7 +31,7 @@ Examples:
3131
mq %s --repo /path/to/protected-main --publish 4 --json
3232
3333
Flags:
34-
`, action, action, action))
34+
`, currentCLIProgramName(), action, action, action))
3535

3636
var repoPath string
3737
var submissionID int64

internal/app/land.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ type landResult struct {
3434
}
3535

3636
func runLand(args []string, stdout io.Writer, stderr io.Writer) error {
37-
fs := flag.NewFlagSet("mainline land", flag.ContinueOnError)
37+
fs := flag.NewFlagSet(currentCLIProgramName()+" land", flag.ContinueOnError)
3838
fs.SetOutput(stderr)
39-
setFlagUsage(fs, `Usage:
40-
mainline land [flags]
39+
setFlagUsage(fs, fmt.Sprintf(`Usage:
40+
%s land [flags]
4141
4242
Submit a topic worktree and wait until it is integrated and published.
4343
@@ -49,7 +49,7 @@ Examples:
4949
mq land --repo /path/to/topic-worktree --json
5050
5151
Flags:
52-
`)
52+
`, currentCLIProgramName()))
5353

5454
var repoPath string
5555
var branch string

internal/app/publish.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ type publishResult struct {
2222
}
2323

2424
func runPublish(args []string, stdout io.Writer, stderr io.Writer) error {
25-
fs := flag.NewFlagSet("mainline publish", flag.ContinueOnError)
25+
fs := flag.NewFlagSet(currentCLIProgramName()+" publish", flag.ContinueOnError)
2626
fs.SetOutput(stderr)
27-
setFlagUsage(fs, `Usage:
28-
mainline publish [flags]
27+
setFlagUsage(fs, fmt.Sprintf(`Usage:
28+
%s publish [flags]
2929
3030
Queue publish of the current protected-branch tip.
3131
@@ -34,7 +34,7 @@ Examples:
3434
mq publish --repo /path/to/protected-main --json
3535
3636
Flags:
37-
`)
37+
`, currentCLIProgramName()))
3838

3939
var repoPath string
4040
var asJSON bool

internal/app/repo.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ func runPlaceholderCommand(command string, args []string, stdout io.Writer) erro
7878
}
7979

8080
func runRepoInit(args []string, stdout io.Writer, stderr io.Writer) error {
81-
fs := flag.NewFlagSet("mainline repo init", flag.ContinueOnError)
81+
fs := flag.NewFlagSet(currentCLIProgramName()+" repo init", flag.ContinueOnError)
8282
fs.SetOutput(stderr)
83-
setFlagUsage(fs, `Usage:
84-
mainline repo init [flags]
83+
setFlagUsage(fs, fmt.Sprintf(`Usage:
84+
%s repo init [flags]
8585
8686
Initialize durable mq state for the current repo and scaffold mainline.toml.
8787
@@ -93,7 +93,7 @@ Then install hooks:
9393
./scripts/install-hooks.sh
9494
9595
Flags:
96-
`)
96+
`, currentCLIProgramName()))
9797

9898
var repoPath string
9999
var protectedBranch string
@@ -210,10 +210,10 @@ Flags:
210210
}
211211

212212
func runRepoShow(args []string, stdout io.Writer, stderr io.Writer) error {
213-
fs := flag.NewFlagSet("mainline repo show", flag.ContinueOnError)
213+
fs := flag.NewFlagSet(currentCLIProgramName()+" repo show", flag.ContinueOnError)
214214
fs.SetOutput(stderr)
215-
setFlagUsage(fs, `Usage:
216-
mainline repo show [flags]
215+
setFlagUsage(fs, fmt.Sprintf(`Usage:
216+
%s repo show [flags]
217217
218218
Show the stored repo config, protected-branch status, and discovered worktrees.
219219
@@ -222,7 +222,7 @@ Examples:
222222
mq repo show --json
223223
224224
Flags:
225-
`)
225+
`, currentCLIProgramName()))
226226

227227
var repoPath string
228228
var asJSON bool
@@ -314,10 +314,10 @@ Flags:
314314
}
315315

316316
func runDoctor(args []string, stdout io.Writer, stderr io.Writer) error {
317-
fs := flag.NewFlagSet("mainline doctor", flag.ContinueOnError)
317+
fs := flag.NewFlagSet(currentCLIProgramName()+" doctor", flag.ContinueOnError)
318318
fs.SetOutput(stderr)
319-
setFlagUsage(fs, `Usage:
320-
mainline doctor [flags]
319+
setFlagUsage(fs, fmt.Sprintf(`Usage:
320+
%s doctor [flags]
321321
322322
Inspect repo health and optionally apply safe automatic recovery steps.
323323
@@ -326,7 +326,7 @@ Examples:
326326
mq doctor --repo /path/to/protected-main --fix --json
327327
328328
Flags:
329-
`)
329+
`, currentCLIProgramName()))
330330

331331
var repoPath string
332332
var asJSON bool

internal/app/run_once.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
)
1919

2020
func runRunOnce(args []string, stdout io.Writer, stderr io.Writer) error {
21-
fs := flag.NewFlagSet("mainline run-once", flag.ContinueOnError)
21+
fs := flag.NewFlagSet(currentCLIProgramName()+" run-once", flag.ContinueOnError)
2222
fs.SetOutput(stderr)
23-
setFlagUsage(fs, `Usage:
24-
mainline run-once [flags]
23+
setFlagUsage(fs, fmt.Sprintf(`Usage:
24+
%s run-once [flags]
2525
2626
Run one serialized integration or publish cycle from the protected worktree.
2727
@@ -30,7 +30,7 @@ Examples:
3030
mq run-once --repo /path/to/protected-main --json
3131
3232
Flags:
33-
`)
33+
`, currentCLIProgramName()))
3434

3535
var repoPath string
3636
var asJSON bool

0 commit comments

Comments
 (0)