Skip to content

Commit d56da2d

Browse files
[Crane: crane-migration-python-to-go-full-apm-cli-rewrite] Iteration 146: fix errcli.go wrong quote transform + mcp install probe handling
Root cause analysis of PYTHON_CLI_CONTRACT_STATUS=1: 1. errcli.go incorrectly transformed 'Error: No such option: --X' into 'Error: No such option '--X'.' (adding single quotes and a trailing period). Python Click 8.2.1 outputs no quotes, no period: just 'Error: No such option: --X'. Remove the transformation block. 2. runMCPInstall skipped dash-prefixed args as name, producing 'Error: Missing argument NAME.' (1 line) for the probe arg. Python Click with ignore_unknown_options=True assigns --definitely-not-an-apm-option to the NAME positional, then forwards to 'apm install' which rejects it with a 4-line error rooted in the install context. Mirror by: accepting dash-prefixed args as name, then emitting install-context unknown-option error so errcli.go produces the correct 4-line output. Actions run: https://github.com/githubnext/apm/actions/runs/28269459014 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1cca8df commit d56da2d

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

cmd/apm/cmd_mcp.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,26 @@ func runMCPInstall(args []string) int {
8383
case "--limit":
8484
i++ // skip value
8585
default:
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 == "" {
86+
// Mirror Python Click ignore_unknown_options=True: any non-flag arg
87+
// (including dash-prefixed) is accepted as NAME positional, just as
88+
// Click assigns it to ctx.args and then to the NAME argument.
89+
if !startsWith(a, "--limit=") && name == "" {
9090
name = a
9191
}
9292
}
9393
}
9494
if name == "" {
9595
fmt.Fprintln(os.Stderr, "Error: Missing argument 'NAME'.")
96+
fmt.Fprintln(os.Stderr, "Try 'apm mcp install --help' for help.")
97+
return 2
98+
}
99+
// Python forwards: cli.main(["install", "--mcp", name, ...], standalone_mode=False)
100+
// When name starts with '-', apm install rejects it as an unknown option.
101+
// Mirror that: emit the install-context unknown-option error so errcli.go
102+
// produces the same 4-line format Python Click generates.
103+
if startsWith(name, "-") {
104+
fmt.Fprintf(os.Stderr, "Error: No such option: %s\n", name)
105+
fmt.Fprintln(os.Stderr, "Try 'apm install --help' for help.")
96106
return 2
97107
}
98108

cmd/apm/errcli.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,9 @@ func (w *clickErrWriter) processLine(line string) {
8383
tryContent := strings.TrimPrefix(line, "Try '")
8484
tryContent = strings.TrimSuffix(strings.TrimRight(tryContent, "\n"), "' for help.")
8585
cmdPath := strings.TrimSuffix(tryContent, " --help")
86-
// Convert Go "Error: No such option: --X" to Click 8.x "Error: No such option '--X'."
86+
// Pass through the error line unchanged -- Python Click 8.x uses
87+
// "Error: No such option: --X" (colon, no quotes, no period).
8788
errLine := w.pending
88-
const errPrefix = "Error: No such option: "
89-
if strings.HasPrefix(errLine, errPrefix) {
90-
opt := strings.TrimRight(strings.TrimPrefix(errLine, errPrefix), "\n")
91-
errLine = "Error: No such option '" + opt + "'.\n"
92-
}
9389
fmt.Fprintf(w.w, "%s\n%s\n%s", usageLine(cmdPath), line, errLine)
9490
w.pending = ""
9591
return

0 commit comments

Comments
 (0)