1010 * @fileoverview CLI entry point for the eval inventory command.
1111 *
1212 * Scans all eval source files, runs the static analyzer on each,
13- * and prints a human-readable inventory report grouped by policy,
14- * file, and suite.
13+ * and prints an inventory report grouped by policy, file, and suite.
1514 *
1615 * Usage:
1716 * npm run eval:inventory
17+ * npm run eval:inventory -- --json
1818 * npm run eval:inventory -- --root /path/to/repo
19+ * npm run eval:inventory -- --root /path/to/repo --json
1920 */
2021
2122import {
2223 collectInventory ,
24+ formatInventoryJson ,
2325 formatInventoryReport ,
2426} from './utils/eval-inventory.js' ;
2527
2628async function main ( ) {
2729 const rootFlagIndex = process . argv . indexOf ( '--root' ) ;
28- const repoRoot =
29- rootFlagIndex !== - 1 && process . argv [ rootFlagIndex + 1 ]
30- ? process . argv [ rootFlagIndex + 1 ]
31- : process . cwd ( ) ;
30+ const rootFlagValue =
31+ rootFlagIndex !== - 1 ? process . argv [ rootFlagIndex + 1 ] : undefined ;
32+ if ( rootFlagIndex !== - 1 && rootFlagValue === undefined ) {
33+ console . error (
34+ 'Error: --root requires a directory path argument but none was provided.' ,
35+ ) ;
36+ process . exit ( 1 ) ;
37+ }
38+ if ( rootFlagValue && rootFlagValue . startsWith ( '--' ) ) {
39+ console . error (
40+ `Error: --root value "${ rootFlagValue } " looks like a flag. Provide a valid directory path.` ,
41+ ) ;
42+ process . exit ( 1 ) ;
43+ }
44+ const repoRoot = rootFlagValue ?? process . cwd ( ) ;
45+
46+ const jsonMode = process . argv . includes ( '--json' ) ;
3247
3348 const result = await collectInventory ( repoRoot ) ;
3449
@@ -37,7 +52,9 @@ async function main() {
3752 process . exit ( 1 ) ;
3853 }
3954
40- console . log ( formatInventoryReport ( result ) ) ;
55+ console . log (
56+ jsonMode ? formatInventoryJson ( result ) : formatInventoryReport ( result ) ,
57+ ) ;
4158}
4259
4360main ( ) . catch ( ( error ) => {
0 commit comments