Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
29 changes: 29 additions & 0 deletions test/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down