Skip to content

Commit ae01a96

Browse files
[Crane: crane-migration-python-to-go-full-apm-cli-rewrite] Iteration 143: fix apm mcp install unknown-option parity
Changes: - cmd/apm/cmd_mcp.go: Fix runMCPInstall to not treat --X args as NAME positional. Python Click's ignore_unknown_options=True treats --X as unknown options (ctx.args), not as NAME. So 'apm mcp install --foo' outputs 'Error: Missing argument NAME.' -- not the 4-line UsageError. - Remove unreachable strings.HasPrefix(name, "-") error block. Run: https://github.com/githubnext/apm/actions/runs/28225237618 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1a51991 commit ae01a96

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

cmd/apm/cmd_mcp.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ func runMCPInstall(args []string) int {
8383
case "--limit":
8484
i++ // skip value
8585
default:
86-
if !startsWith(a, "--limit=") && name == "" {
87-
// Mirror Python's ignore_unknown_options=True: treat any
88-
// unrecognised arg (including --X) as the NAME positional.
86+
// Mirror Python Click: args starting with '-' are unknown options
87+
// (they go to ctx.args via ignore_unknown_options=True and never
88+
// fill the NAME positional). Only non-dash args are positional.
89+
if !startsWith(a, "--limit=") && !startsWith(a, "-") && name == "" {
8990
name = a
9091
}
9192
}
@@ -94,15 +95,6 @@ func runMCPInstall(args []string) int {
9495
fmt.Fprintln(os.Stderr, "Error: Missing argument 'NAME'.")
9596
return 2
9697
}
97-
// Python's build_mcp_entry() raises ValueError for names that fail the MCP
98-
// name regex; Click converts it to UsageError and prints 4 lines to stderr.
99-
if strings.HasPrefix(name, "-") {
100-
fmt.Fprintln(os.Stderr, "Usage: apm mcp install [OPTIONS] NAME")
101-
fmt.Fprintln(os.Stderr, "Try 'apm mcp install --help' for help.")
102-
fmt.Fprintln(os.Stderr, "")
103-
fmt.Fprintf(os.Stderr, "Error: Invalid MCP dependency name '%s': must start with a letter, digit, '@', or '_' and contain only [a-zA-Z0-9._@/:=-] (max 128 chars). Example: 'io.github.acme/cool-server' or 'my-server'.\n", name)
104-
return 2
105-
}
10698

10799
cwd, _ := os.Getwd()
108100
ymlPath, err := findApmYML(cwd)

0 commit comments

Comments
 (0)