Skip to content

Commit 8f55b7c

Browse files
committed
feat: add default directory handling to validate command
- Default to current directory when no patterns provided - Automatically convert directory paths to recursive glob patterns - Handle ".", "./", and explicit directory paths - Maintain backward compatibility with existing file patterns
1 parent f7782fa commit 8f55b7c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/commands/validate.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { glob } from 'glob';
2+
import { statSync } from 'fs';
3+
import { join } from 'path';
24
import { LinkValidator } from '../core/link-validator.js';
35
import { LinkParser } from '../core/link-parser.js';
46
import type { LinkType } from '../types/links.js';
@@ -304,6 +306,23 @@ export async function validateCommand(
304306
patterns: string[],
305307
cliOptions: ValidateCliOptions
306308
): Promise<void> {
309+
// Default to current directory if no patterns provided
310+
let finalPatterns = patterns.length === 0 ? ['.'] : patterns;
311+
312+
// Convert directories to glob patterns
313+
finalPatterns = finalPatterns.map(pattern => {
314+
try {
315+
const stat = statSync(pattern);
316+
if (stat.isDirectory()) {
317+
return join(pattern, '**/*.md');
318+
}
319+
return pattern;
320+
} catch {
321+
// If stat fails, treat as a file pattern
322+
return pattern;
323+
}
324+
});
325+
307326
// Convert CLI options to internal options
308327
const options: ValidateOperationOptions = {
309328
...cliOptions,
@@ -318,7 +337,7 @@ export async function validateCommand(
318337
};
319338

320339
try {
321-
const result = await validateLinks(patterns, options);
340+
const result = await validateLinks(finalPatterns, options);
322341

323342
if (cliOptions.json) {
324343
console.log(JSON.stringify(result, null, 2));

0 commit comments

Comments
 (0)