✨ mm help: the same as mm --help and mm -help (#273)
A first argument `help` is rewritten to `-help`, as `tui`, `acp` and `a2a` are: the flag package prints the same usage on stderr, exit 0. Test comparing the outputs in a child process; docs EN+FR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1388ba2 parent: f4b8126 modified
.tickets/issues/0273-mm-help-an-overview-of-mm-and-its-subcommands.yaml +25 -7 | @@ -1,12 +1,13 @@ | ||
| 1 | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | 2 | id: 273 |
| 3 | 3 | title: "mm help: the same as mm --help and mm -help" |
| 4 | -state: open | |
| 4 | +state: closed | |
| 5 | 5 | author: |
| 6 | 6 | name: k33g |
| 7 | 7 | email: ph.charriere@gmail.com |
| 8 | 8 | createdAt: 2026-11-27T07:30:00.000Z |
| 9 | -updatedAt: 2026-11-27T07:45:00.000Z | |
| 9 | +updatedAt: 2026-11-27T09:00:00.000Z | |
| 10 | +closedAt: 2026-11-27T09:00:00.000Z | |
| 10 | 11 | labels: |
| 11 | 12 | - enhancement |
| 12 | 13 | - kind::feature |
| @@ -83,20 +84,37 @@ tasks: | ||
| 83 | 84 | closedAt: 2026-11-27T07:45:00.000Z |
| 84 | 85 | - id: 2 |
| 85 | 86 | title: "mm help as the first argument = mm --help (same text, stderr, exit 0) — with a test comparing them" |
| 86 | - state: open | |
| 87 | + state: closed | |
| 87 | 88 | priority: medium |
| 88 | 89 | author: |
| 89 | 90 | name: k33g |
| 90 | 91 | email: ph.charriere@gmail.com |
| 91 | 92 | createdAt: 2026-11-27T07:45:00.000Z |
| 92 | - updatedAt: 2026-11-27T07:45:00.000Z | |
| 93 | + updatedAt: 2026-11-27T08:00:00.000Z | |
| 94 | + closedAt: 2026-11-27T08:00:00.000Z | |
| 93 | 95 | - id: 3 |
| 94 | 96 | title: "Docs EN+FR: reference/cli.md" |
| 95 | - state: open | |
| 97 | + state: closed | |
| 96 | 98 | priority: low |
| 97 | 99 | author: |
| 98 | 100 | name: k33g |
| 99 | 101 | email: ph.charriere@gmail.com |
| 100 | 102 | createdAt: 2026-11-27T07:45:00.000Z |
| 101 | - updatedAt: 2026-11-27T07:45:00.000Z | |
| 102 | -comments: [] | |
| 103 | + updatedAt: 2026-11-27T08:00:00.000Z | |
| 104 | + closedAt: 2026-11-27T08:00:00.000Z | |
| 105 | +comments: | |
| 106 | + - id: 1 | |
| 107 | + author: | |
| 108 | + name: k33g | |
| 109 | + email: ph.charriere@gmail.com | |
| 110 | + createdAt: 2026-11-27T08:00:00.000Z | |
| 111 | + body: | | |
| 112 | + Done on branch feature/mm-help (not merged yet): main.go | |
| 113 | + modeWordAsFlag turns a first argument `help` into `-help`, like `tui`, | |
| 114 | + `acp` and `a2a` — the flag package then prints the very same usage. | |
| 115 | + Only the FIRST argument: `mm agent.yaml help` is unchanged. Tests: | |
| 116 | + TestModeWordAsFlag (+2 cases), TestHelpIsTheSameAsDashHelp (child | |
| 117 | + process, a file called `help` in the directory: help, -help, -h give | |
| 118 | + the same stderr as --help, empty stdout, exit 0). Live with the built | |
| 119 | + binary: the three outputs identical (35 lines), exit 0. go test ./..., | |
| 120 | + vet, gofmt clean. Docs EN+FR: reference/cli.md (invocation, -h row). | |
| @@ -1,12 +1,13 @@ | |||
| 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. | 1 | # Managed by IssueSpec. Hand edits are welcome; keep the schema valid. |
| 2 | id: 273 | 2 | id: 273 |
| 3 | title: "mm help: the same as mm --help and mm -help" | 3 | title: "mm help: the same as mm --help and mm -help" |
| 4 | -state: open | 4 | +state: closed |
| 5 | author: | 5 | author: |
| 6 | name: k33g | 6 | name: k33g |
| 7 | email: ph.charriere@gmail.com | 7 | email: ph.charriere@gmail.com |
| 8 | createdAt: 2026-11-27T07:30:00.000Z | 8 | createdAt: 2026-11-27T07:30:00.000Z |
| 9 | -updatedAt: 2026-11-27T07:45:00.000Z | 9 | +updatedAt: 2026-11-27T09:00:00.000Z |
| 10 | +closedAt: 2026-11-27T09:00:00.000Z | ||
| 10 | labels: | 11 | labels: |
| 11 | - enhancement | 12 | - enhancement |
| 12 | - kind::feature | 13 | - kind::feature |
| @@ -83,20 +84,37 @@ tasks: | |||
| 83 | closedAt: 2026-11-27T07:45:00.000Z | 84 | closedAt: 2026-11-27T07:45:00.000Z |
| 84 | - id: 2 | 85 | - id: 2 |
| 85 | title: "mm help as the first argument = mm --help (same text, stderr, exit 0) — with a test comparing them" | 86 | title: "mm help as the first argument = mm --help (same text, stderr, exit 0) — with a test comparing them" |
| 86 | - state: open | 87 | + state: closed |
| 87 | priority: medium | 88 | priority: medium |
| 88 | author: | 89 | author: |
| 89 | name: k33g | 90 | name: k33g |
| 90 | email: ph.charriere@gmail.com | 91 | email: ph.charriere@gmail.com |
| 91 | createdAt: 2026-11-27T07:45:00.000Z | 92 | createdAt: 2026-11-27T07:45:00.000Z |
| 92 | - updatedAt: 2026-11-27T07:45:00.000Z | 93 | + updatedAt: 2026-11-27T08:00:00.000Z |
| 94 | + closedAt: 2026-11-27T08:00:00.000Z | ||
| 93 | - id: 3 | 95 | - id: 3 |
| 94 | title: "Docs EN+FR: reference/cli.md" | 96 | title: "Docs EN+FR: reference/cli.md" |
| 95 | - state: open | 97 | + state: closed |
| 96 | priority: low | 98 | priority: low |
| 97 | author: | 99 | author: |
| 98 | name: k33g | 100 | name: k33g |
| 99 | email: ph.charriere@gmail.com | 101 | email: ph.charriere@gmail.com |
| 100 | createdAt: 2026-11-27T07:45:00.000Z | 102 | createdAt: 2026-11-27T07:45:00.000Z |
| 101 | - updatedAt: 2026-11-27T07:45:00.000Z | 103 | + updatedAt: 2026-11-27T08:00:00.000Z |
| 102 | -comments: [] | 104 | + closedAt: 2026-11-27T08:00:00.000Z |
| 105 | +comments: | ||
| 106 | + - id: 1 | ||
| 107 | + author: | ||
| 108 | + name: k33g | ||
| 109 | + email: ph.charriere@gmail.com | ||
| 110 | + createdAt: 2026-11-27T08:00:00.000Z | ||
| 111 | + body: | | ||
| 112 | + Done on branch feature/mm-help (not merged yet): main.go | ||
| 113 | + modeWordAsFlag turns a first argument `help` into `-help`, like `tui`, | ||
| 114 | + `acp` and `a2a` — the flag package then prints the very same usage. | ||
| 115 | + Only the FIRST argument: `mm agent.yaml help` is unchanged. Tests: | ||
| 116 | + TestModeWordAsFlag (+2 cases), TestHelpIsTheSameAsDashHelp (child | ||
| 117 | + process, a file called `help` in the directory: help, -help, -h give | ||
| 118 | + the same stderr as --help, empty stdout, exit 0). Live with the built | ||
| 119 | + binary: the three outputs identical (35 lines), exit 0. go test ./..., | ||
| 120 | + vet, gofmt clean. Docs EN+FR: reference/cli.md (invocation, -h row). | ||
modified
docs/en/reference/cli.md +2 -1 | @@ -15,6 +15,7 @@ mm sbxinit [flags] (write a sbxenv.yam | ||
| 15 | 15 | mm skillcreate [flags] (write a new skill with a wizard) |
| 16 | 16 | mm tui [<path>] [flags] (same as mm -tui) |
| 17 | 17 | mm acp [<path>] [flags] (same as mm -acp) |
| 18 | +mm help (same as mm -h, mm -help, mm --help) | |
| 18 | 19 | ``` |
| 19 | 20 | |
| 20 | 21 | | Element | Type | Default | Description | |
| @@ -30,7 +31,7 @@ mm acp [<path>] [flags] (same as mm -acp) | ||
| 30 | 31 | | `--about` | bool | `false` | Print what `mm` is — one screen: version, the three front ends, the tools, the model servers, where the project and the docs live — and exit, before the configuration is read. | |
| 31 | 32 | | `--ask <agent>` | string | `""` | Ask the agent `<agent>` (a key of `mmConfigs`) one question and exit; see [Ask mode specifics](#ask-mode-specifics). Like `-p`, works with the config file before or after: `mm agent.yaml --ask lucy -p "…"` and `mm --ask lucy -p "…" agent.yaml` are both valid. | |
| 32 | 33 | | `--ask-with-context <agent>` | string | `""` | Same, sending a conversation read from stdin before the question. | |
| 33 | -| `-h` | — | — | Print the flag usage and exit. | | |
| 34 | +| `-h` | — | — | Print the flag usage and exit. Also written `-help`, `--help`, or `help` as the first argument (ticket 273): the same text, on stderr, exit code 0. | | |
| 34 | 35 | |
| 35 | 36 | ## Version |
| 36 | 37 | |
| @@ -15,6 +15,7 @@ mm sbxinit [flags] (write a sbxenv.yam | |||
| 15 | mm skillcreate [flags] (write a new skill with a wizard) | 15 | mm skillcreate [flags] (write a new skill with a wizard) |
| 16 | mm tui [<path>] [flags] (same as mm -tui) | 16 | mm tui [<path>] [flags] (same as mm -tui) |
| 17 | mm acp [<path>] [flags] (same as mm -acp) | 17 | mm acp [<path>] [flags] (same as mm -acp) |
| 18 | +mm help (same as mm -h, mm -help, mm --help) | ||
| 18 | ``` | 19 | ``` |
| 19 | 20 | ||
| 20 | | Element | Type | Default | Description | | 21 | | Element | Type | Default | Description | |
| @@ -30,7 +31,7 @@ mm acp [<path>] [flags] (same as mm -acp) | |||
| 30 | | `--about` | bool | `false` | Print what `mm` is — one screen: version, the three front ends, the tools, the model servers, where the project and the docs live — and exit, before the configuration is read. | | 31 | | `--about` | bool | `false` | Print what `mm` is — one screen: version, the three front ends, the tools, the model servers, where the project and the docs live — and exit, before the configuration is read. | |
| 31 | | `--ask <agent>` | string | `""` | Ask the agent `<agent>` (a key of `mmConfigs`) one question and exit; see [Ask mode specifics](#ask-mode-specifics). Like `-p`, works with the config file before or after: `mm agent.yaml --ask lucy -p "…"` and `mm --ask lucy -p "…" agent.yaml` are both valid. | | 32 | | `--ask <agent>` | string | `""` | Ask the agent `<agent>` (a key of `mmConfigs`) one question and exit; see [Ask mode specifics](#ask-mode-specifics). Like `-p`, works with the config file before or after: `mm agent.yaml --ask lucy -p "…"` and `mm --ask lucy -p "…" agent.yaml` are both valid. | |
| 32 | | `--ask-with-context <agent>` | string | `""` | Same, sending a conversation read from stdin before the question. | | 33 | | `--ask-with-context <agent>` | string | `""` | Same, sending a conversation read from stdin before the question. | |
| 33 | -| `-h` | — | — | Print the flag usage and exit. | | 34 | +| `-h` | — | — | Print the flag usage and exit. Also written `-help`, `--help`, or `help` as the first argument (ticket 273): the same text, on stderr, exit code 0. | |
| 34 | 35 | ||
| 35 | ## Version | 36 | ## Version |
| 36 | 37 | ||
modified
docs/fr/reference/cli.md +2 -1 | @@ -15,6 +15,7 @@ mm sbxinit [options] (écrire un sbx | ||
| 15 | 15 | mm skillcreate [options] (écrire un nouveau skill avec un assistant) |
| 16 | 16 | mm tui [<chemin>] [options] (identique à mm -tui) |
| 17 | 17 | mm acp [<chemin>] [options] (identique à mm -acp) |
| 18 | +mm help (identique à mm -h, mm -help, mm --help) | |
| 18 | 19 | ``` |
| 19 | 20 | |
| 20 | 21 | | Élément | Type | Défaut | Description | |
| @@ -30,7 +31,7 @@ mm acp [<chemin>] [options] (identique à m | ||
| 30 | 31 | | `--about` | bool | `false` | Affiche ce qu'est `mm` — un écran : version, les trois façades, les outils, les serveurs de modèles, où vivent le projet et la documentation — puis quitte, avant la lecture de la configuration. | |
| 31 | 32 | | `--ask <agent>` | chaîne | `""` | Pose une question à l'agent `<agent>` (une clé de `mmConfigs`) et quitte ; voir [Spécificités du mode ask](#spécificités-du-mode-ask). Comme `-p`, fonctionne avec le fichier de configuration avant ou après : `mm agent.yaml --ask lucy -p "…"` et `mm --ask lucy -p "…" agent.yaml` sont tous deux valides. | |
| 32 | 33 | | `--ask-with-context <agent>` | chaîne | `""` | Pareil, en envoyant avant la question une conversation lue sur stdin. | |
| 33 | -| `-h` | — | — | Affiche l'usage des options et quitte. | | |
| 34 | +| `-h` | — | — | Affiche l'usage des options et quitte. S'écrit aussi `-help`, `--help`, ou `help` comme premier argument (ticket 273) : le même texte, sur stderr, code de sortie 0. | | |
| 34 | 35 | |
| 35 | 36 | ## Version |
| 36 | 37 | |
| @@ -15,6 +15,7 @@ mm sbxinit [options] (écrire un sbx | |||
| 15 | mm skillcreate [options] (écrire un nouveau skill avec un assistant) | 15 | mm skillcreate [options] (écrire un nouveau skill avec un assistant) |
| 16 | mm tui [<chemin>] [options] (identique à mm -tui) | 16 | mm tui [<chemin>] [options] (identique à mm -tui) |
| 17 | mm acp [<chemin>] [options] (identique à mm -acp) | 17 | mm acp [<chemin>] [options] (identique à mm -acp) |
| 18 | +mm help (identique à mm -h, mm -help, mm --help) | ||
| 18 | ``` | 19 | ``` |
| 19 | 20 | ||
| 20 | | Élément | Type | Défaut | Description | | 21 | | Élément | Type | Défaut | Description | |
| @@ -30,7 +31,7 @@ mm acp [<chemin>] [options] (identique à m | |||
| 30 | | `--about` | bool | `false` | Affiche ce qu'est `mm` — un écran : version, les trois façades, les outils, les serveurs de modèles, où vivent le projet et la documentation — puis quitte, avant la lecture de la configuration. | | 31 | | `--about` | bool | `false` | Affiche ce qu'est `mm` — un écran : version, les trois façades, les outils, les serveurs de modèles, où vivent le projet et la documentation — puis quitte, avant la lecture de la configuration. | |
| 31 | | `--ask <agent>` | chaîne | `""` | Pose une question à l'agent `<agent>` (une clé de `mmConfigs`) et quitte ; voir [Spécificités du mode ask](#spécificités-du-mode-ask). Comme `-p`, fonctionne avec le fichier de configuration avant ou après : `mm agent.yaml --ask lucy -p "…"` et `mm --ask lucy -p "…" agent.yaml` sont tous deux valides. | | 32 | | `--ask <agent>` | chaîne | `""` | Pose une question à l'agent `<agent>` (une clé de `mmConfigs`) et quitte ; voir [Spécificités du mode ask](#spécificités-du-mode-ask). Comme `-p`, fonctionne avec le fichier de configuration avant ou après : `mm agent.yaml --ask lucy -p "…"` et `mm --ask lucy -p "…" agent.yaml` sont tous deux valides. | |
| 32 | | `--ask-with-context <agent>` | chaîne | `""` | Pareil, en envoyant avant la question une conversation lue sur stdin. | | 33 | | `--ask-with-context <agent>` | chaîne | `""` | Pareil, en envoyant avant la question une conversation lue sur stdin. | |
| 33 | -| `-h` | — | — | Affiche l'usage des options et quitte. | | 34 | +| `-h` | — | — | Affiche l'usage des options et quitte. S'écrit aussi `-help`, `--help`, ou `help` comme premier argument (ticket 273) : le même texte, sur stderr, code de sortie 0. | |
| 34 | 35 | ||
| 35 | ## Version | 36 | ## Version |
| 36 | 37 | ||
modified
init_assemble_test.go +2 -0 | @@ -52,6 +52,8 @@ func TestModeWordAsFlag(t *testing.T) { | ||
| 52 | 52 | {[]string{"mm", "agent.yaml", "tui"}, []string{"mm", "agent.yaml", "tui"}}, |
| 53 | 53 | {[]string{"mm", "./tui"}, []string{"mm", "./tui"}}, |
| 54 | 54 | {[]string{"mm"}, []string{"mm"}}, |
| 55 | + {[]string{"mm", "help"}, []string{"mm", "-help"}}, | |
| 56 | + {[]string{"mm", "agent.yaml", "help"}, []string{"mm", "agent.yaml", "help"}}, | |
| 55 | 57 | } { |
| 56 | 58 | if got := modeWordAsFlag(c.in); !slices.Equal(got, c.want) { |
| 57 | 59 | t.Errorf("modeWordAsFlag(%q) = %q, want %q", c.in, got, c.want) |
| @@ -52,6 +52,8 @@ func TestModeWordAsFlag(t *testing.T) { | |||
| 52 | {[]string{"mm", "agent.yaml", "tui"}, []string{"mm", "agent.yaml", "tui"}}, | 52 | {[]string{"mm", "agent.yaml", "tui"}, []string{"mm", "agent.yaml", "tui"}}, |
| 53 | {[]string{"mm", "./tui"}, []string{"mm", "./tui"}}, | 53 | {[]string{"mm", "./tui"}, []string{"mm", "./tui"}}, |
| 54 | {[]string{"mm"}, []string{"mm"}}, | 54 | {[]string{"mm"}, []string{"mm"}}, |
| 55 | + {[]string{"mm", "help"}, []string{"mm", "-help"}}, | ||
| 56 | + {[]string{"mm", "agent.yaml", "help"}, []string{"mm", "agent.yaml", "help"}}, | ||
| 55 | } { | 57 | } { |
| 56 | if got := modeWordAsFlag(c.in); !slices.Equal(got, c.want) { | 58 | if got := modeWordAsFlag(c.in); !slices.Equal(got, c.want) { |
| 57 | t.Errorf("modeWordAsFlag(%q) = %q, want %q", c.in, got, c.want) | 59 | t.Errorf("modeWordAsFlag(%q) = %q, want %q", c.in, got, c.want) |
modified
main.go +9 -4 | @@ -110,7 +110,8 @@ func main() { | ||
| 110 | 110 | os.Exit(skillcreate.Main(os.Args[2:], os.Stdin, os.Stdout, skillcreate.Options{Window: tui.RunSkillCreate, Terminal: tui.Terminal})) |
| 111 | 111 | } |
| 112 | 112 | // `mm tui` and `mm acp` (ticket 117): the modes as words too, like |
| 113 | - // `mm init` — `mm tui agent.yaml` is `mm -tui agent.yaml`. | |
| 113 | + // `mm init` — `mm tui agent.yaml` is `mm -tui agent.yaml`. `mm help` | |
| 114 | + // (ticket 273) is `mm -help` the same way. | |
| 114 | 115 | os.Args = modeWordAsFlag(os.Args) |
| 115 | 116 | |
| 116 | 117 | // Handle --prompt/-p flag which can appear after the config file argument |
| @@ -1030,15 +1031,19 @@ func isSbxInit(arg string) bool { | ||
| 1030 | 1031 | return arg == "sbxinit" || arg == "--sbxinit" || arg == "-sbxinit" |
| 1031 | 1032 | } |
| 1032 | 1033 | |
| 1033 | -// modeWordAsFlag turns a first argument `tui` or `acp` into its flag, so the | |
| 1034 | -// rest of main sees one spelling: | |
| 1034 | +// modeWordAsFlag turns a first argument `tui`, `acp`, `a2a` or `help` into | |
| 1035 | +// its flag, so the rest of main sees one spelling: | |
| 1035 | 1036 | // |
| 1036 | 1037 | // modeWordAsFlag([]string{"mm", "tui", "agent.yaml"}) // → mm -tui agent.yaml |
| 1038 | +// modeWordAsFlag([]string{"mm", "help"}) // → mm -help | |
| 1039 | +// | |
| 1040 | +// `mm help` (ticket 273) is exactly `mm -help`: the flag package prints the | |
| 1041 | +// same usage, on stderr, and exits 0. | |
| 1037 | 1042 | // |
| 1038 | 1043 | // Only the first argument is a mode word: `mm agent.yaml tui` still names two |
| 1039 | 1044 | // config files, and a config file called tui is reached as ./tui. |
| 1040 | 1045 | func modeWordAsFlag(args []string) []string { |
| 1041 | - if len(args) < 2 || (args[1] != "tui" && args[1] != "acp" && args[1] != "a2a") { | |
| 1046 | + if len(args) < 2 || (args[1] != "tui" && args[1] != "acp" && args[1] != "a2a" && args[1] != "help") { | |
| 1042 | 1047 | return args |
| 1043 | 1048 | } |
| 1044 | 1049 | return append([]string{args[0], "-" + args[1]}, args[2:]...) |
| @@ -110,7 +110,8 @@ func main() { | |||
| 110 | os.Exit(skillcreate.Main(os.Args[2:], os.Stdin, os.Stdout, skillcreate.Options{Window: tui.RunSkillCreate, Terminal: tui.Terminal})) | 110 | os.Exit(skillcreate.Main(os.Args[2:], os.Stdin, os.Stdout, skillcreate.Options{Window: tui.RunSkillCreate, Terminal: tui.Terminal})) |
| 111 | } | 111 | } |
| 112 | // `mm tui` and `mm acp` (ticket 117): the modes as words too, like | 112 | // `mm tui` and `mm acp` (ticket 117): the modes as words too, like |
| 113 | - // `mm init` — `mm tui agent.yaml` is `mm -tui agent.yaml`. | 113 | + // `mm init` — `mm tui agent.yaml` is `mm -tui agent.yaml`. `mm help` |
| 114 | + // (ticket 273) is `mm -help` the same way. | ||
| 114 | os.Args = modeWordAsFlag(os.Args) | 115 | os.Args = modeWordAsFlag(os.Args) |
| 115 | 116 | ||
| 116 | // Handle --prompt/-p flag which can appear after the config file argument | 117 | // Handle --prompt/-p flag which can appear after the config file argument |
| @@ -1030,15 +1031,19 @@ func isSbxInit(arg string) bool { | |||
| 1030 | return arg == "sbxinit" || arg == "--sbxinit" || arg == "-sbxinit" | 1031 | return arg == "sbxinit" || arg == "--sbxinit" || arg == "-sbxinit" |
| 1031 | } | 1032 | } |
| 1032 | 1033 | ||
| 1033 | -// modeWordAsFlag turns a first argument `tui` or `acp` into its flag, so the | 1034 | +// modeWordAsFlag turns a first argument `tui`, `acp`, `a2a` or `help` into |
| 1034 | -// rest of main sees one spelling: | 1035 | +// its flag, so the rest of main sees one spelling: |
| 1035 | // | 1036 | // |
| 1036 | // modeWordAsFlag([]string{"mm", "tui", "agent.yaml"}) // → mm -tui agent.yaml | 1037 | // modeWordAsFlag([]string{"mm", "tui", "agent.yaml"}) // → mm -tui agent.yaml |
| 1038 | +// modeWordAsFlag([]string{"mm", "help"}) // → mm -help | ||
| 1039 | +// | ||
| 1040 | +// `mm help` (ticket 273) is exactly `mm -help`: the flag package prints the | ||
| 1041 | +// same usage, on stderr, and exits 0. | ||
| 1037 | // | 1042 | // |
| 1038 | // Only the first argument is a mode word: `mm agent.yaml tui` still names two | 1043 | // Only the first argument is a mode word: `mm agent.yaml tui` still names two |
| 1039 | // config files, and a config file called tui is reached as ./tui. | 1044 | // config files, and a config file called tui is reached as ./tui. |
| 1040 | func modeWordAsFlag(args []string) []string { | 1045 | func modeWordAsFlag(args []string) []string { |
| 1041 | - if len(args) < 2 || (args[1] != "tui" && args[1] != "acp" && args[1] != "a2a") { | 1046 | + if len(args) < 2 || (args[1] != "tui" && args[1] != "acp" && args[1] != "a2a" && args[1] != "help") { |
| 1042 | return args | 1047 | return args |
| 1043 | } | 1048 | } |
| 1044 | return append([]string{args[0], "-" + args[1]}, args[2:]...) | 1049 | return append([]string{args[0], "-" + args[1]}, args[2:]...) |
modified
main_test.go +43 -0 | @@ -5,6 +5,7 @@ import ( | ||
| 5 | 5 | "errors" |
| 6 | 6 | "os" |
| 7 | 7 | "os/exec" |
| 8 | + "path/filepath" | |
| 8 | 9 | "slices" |
| 9 | 10 | "strings" |
| 10 | 11 | "testing" |
| @@ -100,3 +101,45 @@ func withoutEnv(names ...string) []string { | ||
| 100 | 101 | } |
| 101 | 102 | return out |
| 102 | 103 | } |
| 104 | + | |
| 105 | +// Ticket 273: `mm help` is exactly `mm --help` and `mm -help` — the same | |
| 106 | +// text on stderr, nothing on stdout, exit code 0 — even with a file called | |
| 107 | +// `help` in the directory. The real main runs in a child process, as above. | |
| 108 | +func TestHelpIsTheSameAsDashHelp(t *testing.T) { | |
| 109 | + if os.Getenv("MM_TEST_RUN_MAIN") == "1" { | |
| 110 | + os.Args = append([]string{"mm"}, strings.Fields(os.Getenv("MM_TEST_ARGS"))...) | |
| 111 | + main() | |
| 112 | + os.Exit(0) | |
| 113 | + } | |
| 114 | + dir := t.TempDir() | |
| 115 | + if err := os.WriteFile(filepath.Join(dir, "help"), []byte("provider: dmr\nmodel: x\n"), 0o644); err != nil { | |
| 116 | + t.Fatal(err) | |
| 117 | + } | |
| 118 | + run := func(args string) (string, string, int) { | |
| 119 | + cmd := exec.Command(os.Args[0], "-test.run=^TestHelpIsTheSameAsDashHelp$") | |
| 120 | + cmd.Dir = dir | |
| 121 | + cmd.Env = append(withoutEnv("AGENT_CONFIG", "MM_CONFIG"), "MM_TEST_RUN_MAIN=1", "MM_TEST_ARGS="+args) | |
| 122 | + var stdout, stderr bytes.Buffer | |
| 123 | + cmd.Stdout, cmd.Stderr = &stdout, &stderr | |
| 124 | + cmd.Stdin = strings.NewReader("") | |
| 125 | + err := cmd.Run() | |
| 126 | + code := 0 | |
| 127 | + var exit *exec.ExitError | |
| 128 | + if errors.As(err, &exit) { | |
| 129 | + code = exit.ExitCode() | |
| 130 | + } else if err != nil { | |
| 131 | + t.Fatal(err) | |
| 132 | + } | |
| 133 | + return stdout.String(), stderr.String(), code | |
| 134 | + } | |
| 135 | + _, want, wantCode := run("--help") | |
| 136 | + if wantCode != 0 || !strings.Contains(want, "Usage of ") || !strings.Contains(want, "-version") { | |
| 137 | + t.Fatalf("mm --help: exit %d, stderr %q", wantCode, want) | |
| 138 | + } | |
| 139 | + for _, args := range []string{"help", "-help", "-h"} { | |
| 140 | + stdout, stderr, code := run(args) | |
| 141 | + if stderr != want || stdout != "" || code != 0 { | |
| 142 | + t.Errorf("mm %s: exit %d, stdout %q, stderr differs from mm --help: %v", args, code, stdout, stderr != want) | |
| 143 | + } | |
| 144 | + } | |
| 145 | +} | |
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | "errors" | 5 | "errors" |
| 6 | "os" | 6 | "os" |
| 7 | "os/exec" | 7 | "os/exec" |
| 8 | + "path/filepath" | ||
| 8 | "slices" | 9 | "slices" |
| 9 | "strings" | 10 | "strings" |
| 10 | "testing" | 11 | "testing" |
| @@ -100,3 +101,45 @@ func withoutEnv(names ...string) []string { | |||
| 100 | } | 101 | } |
| 101 | return out | 102 | return out |
| 102 | } | 103 | } |
| 104 | + | ||
| 105 | +// Ticket 273: `mm help` is exactly `mm --help` and `mm -help` — the same | ||
| 106 | +// text on stderr, nothing on stdout, exit code 0 — even with a file called | ||
| 107 | +// `help` in the directory. The real main runs in a child process, as above. | ||
| 108 | +func TestHelpIsTheSameAsDashHelp(t *testing.T) { | ||
| 109 | + if os.Getenv("MM_TEST_RUN_MAIN") == "1" { | ||
| 110 | + os.Args = append([]string{"mm"}, strings.Fields(os.Getenv("MM_TEST_ARGS"))...) | ||
| 111 | + main() | ||
| 112 | + os.Exit(0) | ||
| 113 | + } | ||
| 114 | + dir := t.TempDir() | ||
| 115 | + if err := os.WriteFile(filepath.Join(dir, "help"), []byte("provider: dmr\nmodel: x\n"), 0o644); err != nil { | ||
| 116 | + t.Fatal(err) | ||
| 117 | + } | ||
| 118 | + run := func(args string) (string, string, int) { | ||
| 119 | + cmd := exec.Command(os.Args[0], "-test.run=^TestHelpIsTheSameAsDashHelp$") | ||
| 120 | + cmd.Dir = dir | ||
| 121 | + cmd.Env = append(withoutEnv("AGENT_CONFIG", "MM_CONFIG"), "MM_TEST_RUN_MAIN=1", "MM_TEST_ARGS="+args) | ||
| 122 | + var stdout, stderr bytes.Buffer | ||
| 123 | + cmd.Stdout, cmd.Stderr = &stdout, &stderr | ||
| 124 | + cmd.Stdin = strings.NewReader("") | ||
| 125 | + err := cmd.Run() | ||
| 126 | + code := 0 | ||
| 127 | + var exit *exec.ExitError | ||
| 128 | + if errors.As(err, &exit) { | ||
| 129 | + code = exit.ExitCode() | ||
| 130 | + } else if err != nil { | ||
| 131 | + t.Fatal(err) | ||
| 132 | + } | ||
| 133 | + return stdout.String(), stderr.String(), code | ||
| 134 | + } | ||
| 135 | + _, want, wantCode := run("--help") | ||
| 136 | + if wantCode != 0 || !strings.Contains(want, "Usage of ") || !strings.Contains(want, "-version") { | ||
| 137 | + t.Fatalf("mm --help: exit %d, stderr %q", wantCode, want) | ||
| 138 | + } | ||
| 139 | + for _, args := range []string{"help", "-help", "-h"} { | ||
| 140 | + stdout, stderr, code := run(args) | ||
| 141 | + if stderr != want || stdout != "" || code != 0 { | ||
| 142 | + t.Errorf("mm %s: exit %d, stdout %q, stderr differs from mm --help: %v", args, code, stdout, stderr != want) | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | +} | ||