Skip to content

Commit 95c91b8

Browse files
authored
Merge pull request #2140 from Lowpower/cursor/cli-help-format-json-cb65
feat(cli): point top-level cli --help at --format json
2 parents e783f73 + 2f557f5 commit 95c91b8

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎src/cli/cli.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ const char *cbm_cli_get_version(void);
2727

2828
/* ── CLI tool arguments (flags / --args-file / --help) ────────── */
2929

30+
/* Top-level `cli --help` text printed by run_cli() in src/main.c.
31+
* Documents tool-level --format without adding a session-wide flag (#2102). */
32+
#define CBM_CLI_USAGE \
33+
"Usage: codebase-memory-mcp cli [--quiet] [--progress] [--verbose] [--json] <tool_name> " \
34+
"[json_args]\n" \
35+
" --quiet Show errors only; cannot combine with --progress or outer --verbose\n" \
36+
" --progress Show lifecycle progress even when stderr is redirected\n" \
37+
" --verbose Include informational logs (preserves CBM_LOG_LEVEL=debug)\n" \
38+
" --json Print the raw MCP result envelope\n" \
39+
" Tools that accept format support --format tree|json (default: tree).\n" \
40+
" --format json prints payload JSON; outer --json prints the full MCP envelope.\n"
41+
3042
/* Convert `--flag value` / `--flag=value` / bare-boolean `--flag` arguments for
3143
* a tool into a JSON arguments object string, using the tool's input_schema to
3244
* type values (string/integer/boolean) and to collect repeated flags into

‎src/main.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,7 @@ static bool client_start_parent_watchdog(DWORD initial_ppid) {
675675

676676
/* ── CLI mode ───────────────────────────────────────────────────── */
677677

678-
#define CLI_USAGE \
679-
"Usage: codebase-memory-mcp cli [--quiet] [--progress] [--verbose] [--json] <tool_name> " \
680-
"[json_args]\n" \
681-
" --quiet Show errors only; cannot combine with --progress or outer --verbose\n" \
682-
" --progress Show lifecycle progress even when stderr is redirected\n" \
683-
" --verbose Include informational logs (preserves CBM_LOG_LEVEL=debug)\n" \
684-
" --json Print the raw MCP result envelope\n"
678+
#define CLI_USAGE CBM_CLI_USAGE /* `cli --help`; wording lives in cli.h (#2102) */
685679

686680
/* Extract text content from MCP tool result envelope and print it.
687681
* MCP results: {"content":[{"type":"text","text":"..."}],"isError":...}

‎tests/test_cli.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15336,6 +15336,21 @@ TEST(cli_print_tool_help_issue680) {
1533615336
PASS();
1533715337
}
1533815338

15339+
/* #2102: top-level `cli --help` (CLI_USAGE) must point at tool-level
15340+
* `--format json` and distinguish it from outer `--json`. This is help-only:
15341+
* the usage synopsis still has no session-wide --format / CBM_CLI_FORMAT. */
15342+
TEST(cli_usage_points_to_tool_format_json_issue2102) {
15343+
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--format tree|json"));
15344+
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "payload JSON"));
15345+
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "full MCP envelope"));
15346+
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "--json Print the raw MCP result envelope"));
15347+
ASSERT_NOT_NULL(strstr(CBM_CLI_USAGE, "cli [--quiet] [--progress] [--verbose] [--json] "
15348+
"<tool_name>"));
15349+
ASSERT_NULL(strstr(CBM_CLI_USAGE, "[--format"));
15350+
ASSERT_NULL(strstr(CBM_CLI_USAGE, "CBM_CLI_FORMAT"));
15351+
PASS();
15352+
}
15353+
1533915354
/* #1359: `cli <tool>` with no argument-bearing token used to slurp stdin to EOF
1534015355
* for ANY non-terminal stdin. The ordinary automation caller never sends that
1534115356
* EOF — Node's child_process.spawn defaults to stdio:['pipe','pipe','pipe'] and
@@ -16376,6 +16391,7 @@ SUITE(cli) {
1637616391
RUN_TEST(cli_build_args_json_key_equals_value_issue680);
1637716392
RUN_TEST(cli_build_args_json_bad_positional_errors_issue680);
1637816393
RUN_TEST(cli_print_tool_help_issue680);
16394+
RUN_TEST(cli_usage_points_to_tool_format_json_issue2102);
1637916395

1638016396
/* Stdin argument gate (#1359) */
1638116397
RUN_TEST(cli_zero_argument_tool_never_reads_stdin_issue1359);

0 commit comments

Comments
 (0)