diff --git a/src/Sabik/DIContainer.ts b/src/Sabik/DIContainer.ts index ca71797..f2bf00a 100644 --- a/src/Sabik/DIContainer.ts +++ b/src/Sabik/DIContainer.ts @@ -10,7 +10,8 @@ import { CSS } from '../Reporter/HTML/FileBuilder/CSS'; import { HTML } from '../Reporter/HTML/FileBuilder/HTML'; import { Event } from '../Reporter/HTML/FileBuilder/Event'; import { EntryPoint } from '../Reporter/HTML/FileBuilder/EntryPoint'; -import { Writer } from '../Reporter/HTML/Writer'; +import { CSV } from '../Reporter/CSV/FileBuilder/CSV'; +import { Writer } from '../Reporter/Writer'; import { Sabik } from './Sabik'; import { Reporter } from './Reporter'; import { PHP } from './Language/PHP'; @@ -52,6 +53,7 @@ container.bind(Types.outputFileBuilder).to(HTML).whenAnyAncestorNam container.bind(Types.outputFileBuilder).to(Event).whenAnyAncestorNamed('HTML'); container.bind(Types.outputFileBuilder).to(EntryPoint).whenAnyAncestorNamed('HTML'); container.bind(Types.outputFileBuilder).to(JSON).whenAnyAncestorNamed('JSON'); +container.bind(Types.outputFileBuilder).to(CSV).whenAnyAncestorNamed('CSV'); container.bind(Types.reporter).to(ReporterImp); container.bind(Sabik).toSelf(); container.bind(LanguageAnalyzer).to(PHP); diff --git a/src/index.ts b/src/index.ts index 2db0ced..520b215 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,15 +9,26 @@ import { Command, Option } from 'commander'; const program = new Command(); program - .addOption(new Option('-t, --outputFormat ', 'output report format. HTML or JSON. default: HTML').choices(['HTML', 'JSON']).default('HTML')) - .requiredOption('--excludes ', 'exclude patterns is separated by a comma. example: .test.ts$,.spec.ts$', '$^') + .addOption( + new Option('-t, --outputFormat ', 'output report format. default: HTML') + .choices(['HTML', 'JSON', 'CSV']) + .default('HTML') + ) + .requiredOption( + '--excludes ', + 'exclude patterns is separated by a comma. example: .test.ts$,.spec.ts$', + '$^' + ) .requiredOption('--matches ', 'match patterns. example: .ts$', '.*') - .option('-o, --outputReportPath ', `output report path. -For HTML, specify the directory, and for JSON, specify the file.`) + .option( + '-o, --outputReportPath ', + `output report path. +For HTML or CSV, specify the directory, and for JSON, specify the file.` + ) .arguments('[targetPath]') .description('This is source code metrics tool.') .action(async (targetPath?: string, options?) => { - const outputReportPath = options.outputReportPath ?? (options.outputFormat === 'HTML') ? './sabik_report' : null; + const outputReportPath = options.outputReportPath ?? options.outputFormat === 'JSON' ? null : './sabik_report'; const outputPath = outputReportPath !== null ? resolve(outputReportPath) : null; const analyzedTarget = resolve(targetPath ?? './'); const excludes = (options.excludes).split(',').map((row) => new RegExp(row)); @@ -40,7 +51,6 @@ For HTML, specify the directory, and for JSON, specify the file.`) }); export = { - run: (version: string, argv: string[]) => program - .version(version, '-v, --version', 'show CLI version.') - .parseAsync(argv), + run: (version: string, argv: string[]) => + program.version(version, '-v, --version', 'show CLI version.').parseAsync(argv), };