@@ -14,16 +14,16 @@ import {
1414 generateVulnerabilityFixBySeverityChartData ,
1515 generateVulnerabilityFixTimelinessChartData
1616} from './chart-generator'
17+ import os from "os" ;
1718
1819export const metricsCommand = new Command ( )
1920 . name ( 'metrics' )
2021 . description ( 'Run metrics on dependency history and optionally generate charts' )
21- . argument ( '<historyFolder>' , 'Folder where the base input/output folders are located' )
2222 . option ( '--inputDir <inputDir>' , 'Directory to look for input .json files' , '' )
23- . option ( '--results, -r <resultsFolder>' , 'Folder to save results in' , 'results' )
23+ . option ( '--results <resultsFolder>' , 'Folder to save results in' , 'results' )
2424 . option ( '--metric <metricType>' , 'Metric type to calculate' )
2525 . option ( '--chart' , 'Generate chart visualization' , false )
26- . option ( '--chartType <chartType>' , 'Chart type (bar | line | stacked | stacked-area)' , 'bar ')
26+ . option ( '--chartType <chartType>' , 'Chart types to generate (bar, line, stacked, stacked-area)' )
2727 . option ( '--inputFiles <inputFiles...>' , 'List of input files to use (without .json)' )
2828 . action ( runMetrics ) ;
2929
@@ -75,9 +75,17 @@ function isValidMetricType(metric: string): metric is MetricType {
7575 return metric in metricsRegistry ;
7676}
7777
78- export async function runMetrics ( historyFolder : string , options : MetricOptions ) : Promise < void > {
78+ export async function runMetrics ( options : MetricOptions ) : Promise < void > {
79+ const homeDir = os . homedir ( ) ;
7980 const metricType = options . metric ;
8081
82+ // Ensure chartType is always an array with a default value
83+ if ( ! options . chartType || ! Array . isArray ( options . chartType ) ) {
84+ options . chartType = options . chartType ? [ options . chartType as any ] : [ 'bar' ] ;
85+ }
86+
87+ console . log ( 'Chart types:' , options . chartType ) ;
88+
8189 if ( ! isValidMetricType ( metricType ) ) {
8290 console . error ( `❌ Unknown metric type: ${ metricType } ` ) ;
8391 return ;
@@ -90,8 +98,8 @@ export async function runMetrics(historyFolder: string, options: MetricOptions):
9098 return ;
9199 }
92100
93- const inputBase = path . join ( historyFolder , options . inputDir || '' ) ;
94- const outputBase = path . join ( historyFolder , options . results ) ;
101+ const inputBase = path . join ( homeDir , options . inputDir || '' ) ;
102+ const outputBase = path . join ( homeDir , options . results ) ;
95103 fs . mkdirSync ( outputBase , { recursive : true } ) ;
96104
97105 let libraryInfo : any = undefined ;
0 commit comments