From 82333954f6242bf6fabe87ef0f470053de9e9aca Mon Sep 17 00:00:00 2001 From: sh962214-hub Date: Sun, 7 Jun 2026 21:56:22 -0600 Subject: [PATCH] fix(cli): support ui5mcp help flag --- src/cli.ts | 14 +++++++++++++- test/lib/cli.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index b396cddf..b867d0be 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,6 +1,18 @@ import Server from "./server.js"; -if (process.argv.length > 2) { +function printUsage(): void { + process.stdout.write("Usage: ui5mcp\n"); + process.stdout.write("\n"); + process.stdout.write("Options:\n"); + process.stdout.write(" -h, --help Show this help message\n"); +} + +const args = process.argv.slice(2); + +if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) { + printUsage(); + process.exit(0); +} else if (args.length > 0) { process.stderr.write("\n"); process.stderr.write("Unexpected arguments: This command does not accept any arguments.\n"); process.stderr.write("Usage: ui5mcp\n"); diff --git a/test/lib/cli.ts b/test/lib/cli.ts index e54ce545..51f1f71c 100644 --- a/test/lib/cli.ts +++ b/test/lib/cli.ts @@ -91,6 +91,35 @@ test.serial("CLI handles server connection errors", async (t) => { t.true(serverInstance.connect.calledOnce); }); +test.serial("CLI prints help when help flag is provided", async (t) => { + const {sinon, exitStub} = t.context; + + // Mock stdout.write to capture help output + const stdoutWriteStub = sinon.stub(process.stdout, "write"); + + // Add help flag to process.argv + process.argv.push("--help"); + + // Mock the Server import in cli - it shouldn't be called + await esmock("../../src/cli.js", { + "../../src/server.js": { + default: t.context.ServerConstructor, + }, + }); + + // Verify process.exit was called with code 0 + t.true(exitStub.calledOnce); + t.true(exitStub.calledWith(0)); + + // Verify usage was written to stdout + t.true(stdoutWriteStub.calledWith("Usage: ui5mcp\n")); + t.true(stdoutWriteStub.calledWith("Options:\n")); + t.true(stdoutWriteStub.calledWith(" -h, --help Show this help message\n")); + + // Verify Server constructor was not called + t.false(t.context.ServerConstructor.called); +}); + test.serial("CLI exits with error when arguments are provided", async (t) => { const {sinon, exitStub} = t.context;