Skip to content

Commit 0893cff

Browse files
committed
Add --path option to TypeScript CLI layer
- Add --path/-p option to Commander CLI in npx/src/index.ts - Make --url and --path mutually exclusive with validation - Update ReviewOptions interface to support both modes - Skip GitHub token requirement for local path mode - Pass --path to Python CLI when provided instead of --url - All three files (index.ts, cli.ts, python-runner.ts) updated consistently Agent-Id: agent-878b18ab-2ad7-486a-9f3a-56e26a705499
1 parent 962f8dd commit 0893cff

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

npx/src/cli.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
} from './python-runner.js';
1616

1717
export interface ReviewOptions {
18-
url: string;
18+
url?: string;
19+
path?: string;
1920
question?: string;
2021
output: string;
2122
quiet?: boolean;
@@ -26,19 +27,23 @@ export interface ReviewOptions {
2627
}
2728

2829
export async function runReview(options: ReviewOptions): Promise<void> {
29-
const { url, question, output, quiet = false, model, api, githubToken, expert = false } = options;
30+
const { url, path, question, output, quiet = false, model, api, githubToken, expert = false } = options;
3031

3132
try {
3233

3334
// 4. Get API key
3435
const apiKey = await getApiKey(api);
3536

36-
// 5. Get GitHub token (required for code search API)
37-
const ghToken = await getGitHubToken(githubToken, true);
37+
// 5. Get GitHub token only if using URL mode (not required for local path mode)
38+
let ghToken: string | undefined;
39+
if (url) {
40+
ghToken = await getGitHubToken(githubToken, true);
41+
}
3842

3943
// 6. Run the review
4044
if (!quiet) {
41-
console.log(chalk.cyan(`\n 🔍 Reviewing: ${url}`));
45+
const target = url || path;
46+
console.log(chalk.cyan(`\n 🔍 Reviewing: ${target}`));
4247
if (expert) {
4348
console.log(chalk.cyan(` Mode: Expert Code Review (SOLID, Security, Code Quality)\n`));
4449
} else if (question) {
@@ -48,6 +53,7 @@ export async function runReview(options: ReviewOptions): Promise<void> {
4853

4954
const result = await runPythonReview({
5055
url,
56+
path,
5157
question,
5258
output,
5359
quiet,

npx/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ program
1616

1717
program
1818
.command('review')
19-
.description('Review a GitHub PR or Issue')
20-
.requiredOption('-u, --url <url>', 'GitHub PR or Issue URL')
19+
.description('Review a GitHub PR/Issue or local directory')
20+
.option('-u, --url <url>', 'GitHub PR or Issue URL')
21+
.option('-p, --path <path>', 'Local directory path to review')
2122
.option('-q, --question <question>', 'Question to ask about the PR/Issue (optional with --expert)')
2223
.option('--expert', 'Run expert code review (SOLID, Security, Performance, Code Quality)')
2324
.option('-o, --output <format>', 'Output format: text, markdown, json', 'text')
@@ -26,6 +27,15 @@ program
2627
.option('--api <key>', 'Gemini API key (defaults to GEMINI_API_KEY env var)')
2728
.option('--github-token <token>', 'GitHub token for private repos (defaults to GITHUB_TOKEN env var)')
2829
.action(async (options) => {
30+
// Validate mutual exclusion: exactly one of --url or --path must be provided
31+
if (!options.url && !options.path) {
32+
console.error('Error: Either --url or --path must be provided');
33+
process.exit(1);
34+
}
35+
if (options.url && options.path) {
36+
console.error('Error: --url and --path are mutually exclusive');
37+
process.exit(1);
38+
}
2939
await runReview(options);
3040
});
3141

npx/src/python-runner.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ export async function installAsyncReview(systemPython: string, quiet: boolean =
251251
}
252252

253253
export interface RunOptions {
254-
url: string;
254+
url?: string;
255+
path?: string;
255256
question?: string;
256257
output: string;
257258
quiet: boolean;
@@ -282,10 +283,17 @@ export async function runPythonReview(options: RunOptions): Promise<string> {
282283
const args = [
283284
'-m', 'cli.main',
284285
'review',
285-
'--url', options.url,
286-
'--output', options.output,
287286
];
288287

288+
// Add either --url or --path (mutually exclusive)
289+
if (options.url) {
290+
args.push('--url', options.url);
291+
} else if (options.path) {
292+
args.push('--path', options.path);
293+
}
294+
295+
args.push('--output', options.output);
296+
289297
// Add question if provided
290298
if (options.question) {
291299
args.push('-q', options.question);

0 commit comments

Comments
 (0)