Skip to content

Commit

Permalink
feat: add CSV report format.
Browse files Browse the repository at this point in the history
  • Loading branch information
ytetsuro committed Apr 17, 2022
1 parent d24090a commit 856dfdc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/Sabik/DIContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,6 +53,7 @@ container.bind<FileBuilder>(Types.outputFileBuilder).to(HTML).whenAnyAncestorNam
container.bind<FileBuilder>(Types.outputFileBuilder).to(Event).whenAnyAncestorNamed('HTML');
container.bind<FileBuilder>(Types.outputFileBuilder).to(EntryPoint).whenAnyAncestorNamed('HTML');
container.bind<FileBuilder>(Types.outputFileBuilder).to(JSON).whenAnyAncestorNamed('JSON');
container.bind<FileBuilder>(Types.outputFileBuilder).to(CSV).whenAnyAncestorNamed('CSV');
container.bind<Reporter>(Types.reporter).to(ReporterImp);
container.bind<Sabik>(Sabik).toSelf();
container.bind<LanguageAnalyzer>(LanguageAnalyzer).to(PHP);
Expand Down
26 changes: 18 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ import { Command, Option } from 'commander';

const program = new Command();
program
.addOption(new Option('-t, --outputFormat <format>', 'output report format. HTML or JSON. default: HTML').choices(['HTML', 'JSON']).default('HTML'))
.requiredOption('--excludes <patterns...>', 'exclude patterns is separated by a comma. example: .test.ts$,.spec.ts$', '$^')
.addOption(
new Option('-t, --outputFormat <format>', 'output report format. default: HTML')
.choices(['HTML', 'JSON', 'CSV'])
.default('HTML')
)
.requiredOption(
'--excludes <patterns...>',
'exclude patterns is separated by a comma. example: .test.ts$,.spec.ts$',
'$^'
)
.requiredOption('--matches <pattern>', 'match patterns. example: .ts$', '.*')
.option('-o, --outputReportPath <path>', `output report path.
For HTML, specify the directory, and for JSON, specify the file.`)
.option(
'-o, --outputReportPath <path>',
`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 = (<string>options.excludes).split(',').map((row) => new RegExp(row));
Expand All @@ -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),
};

0 comments on commit 856dfdc

Please sign in to comment.