Skip to content

Commit ad63d08

Browse files
committed
feat: add support for --version option, catch unsupported options
1 parent 842d7d8 commit ad63d08

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: files-to-prompt.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,16 @@ describe('files-to-prompt.ts', () => {
256256
const filePathsFromStdin = parseFilePathsFromStdin(stdinData);
257257
expect(filePathsFromStdin).toEqual(['file1.txt', 'file2.txt']);
258258
});
259+
260+
test('should output version string when --version is passed', async () => {
261+
await main(['--version']);
262+
expect(stdoutOutput).toContain(`files-to-prompt.ts version`);
263+
expect(stderrOutput).toBeEmpty();
264+
});
265+
266+
test('should output error for unsupported options', async () => {
267+
await main(['--unsupported-option']);
268+
expect(stdoutOutput).toBeEmpty();
269+
expect(stderrOutput).toContain('Unsupported option');
270+
});
259271
});

Diff for: files-to-prompt.ts

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import fs from 'node:fs';
44
import path from 'node:path';
55

6+
const VERSION = '0.2.0';
7+
68
/**
79
* Represents the configuration for the file processing.
810
* @interface ProcessingConfig
@@ -281,6 +283,9 @@ export async function main( args: string[] ): Promise<void> {
281283
for (let i = 0; i < args.length; i++) {
282284
const arg = args[i];
283285
switch (arg) {
286+
case '--version':
287+
output(`files-to-prompt.ts version ${VERSION}`);
288+
return;
284289
case '--include-hidden':
285290
config.includeHidden = true;
286291
break;
@@ -297,6 +302,10 @@ export async function main( args: string[] ): Promise<void> {
297302
}
298303
break;
299304
default:
305+
if (arg.startsWith('-')) {
306+
error(`Error: Unsupported option '${arg}'`);
307+
return;
308+
}
300309
pathsToProcess.push(arg);
301310
}
302311
}

0 commit comments

Comments
 (0)