Skip to content

Commit

Permalink
fix: Report errors from setting bad options on CLI
Browse files Browse the repository at this point in the history
Closes #1237
  • Loading branch information
Gerrit0 committed Mar 18, 2020
1 parent 508f8ba commit a2e4db1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
10 changes: 6 additions & 4 deletions src/lib/utils/options/readers/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class ArgumentsReader implements OptionsReader {
const seen = new Set<string>();
let index = 0;

const error = (error: Error) => logger.error(error.message);

while (index < this.args.length) {
const name = this.args[index];
const decl = name.startsWith('-')
Expand All @@ -30,19 +32,19 @@ export class ArgumentsReader implements OptionsReader {
container.setValue(
decl.name,
(container.getValue(decl.name) as string[]).concat(this.args[index])
);
).mapErr(error);
} else if (decl.type === ParameterType.Boolean) {
const value = String(this.args[index]).toLowerCase();

if (value === 'true' || value === 'false') {
container.setValue(decl.name, value === 'true');
container.setValue(decl.name, value === 'true').mapErr(error);
} else {
container.setValue(decl.name, true);
container.setValue(decl.name, true).mapErr(error);
// Bool option didn't consume the next argument as expected.
index--;
}
} else {
container.setValue(decl.name, this.args[index]);
container.setValue(decl.name, this.args[index]).mapErr(error);
}
seen.add(decl.name);
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/test/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ describe('Converter', function() {
const checks: [string, () => void, () => void][] = [
['specs', () => { }, () => { }],
['specs.d',
() => app.options.setValue('includeDeclarations', true),
() => app.options.setValue('includeDeclarations', false)
() => app.options.setValue('includeDeclarations', true).unwrap(),
() => app.options.setValue('includeDeclarations', false).unwrap()
],
['specs-without-exported',
() => app.options.setValue('excludeNotExported', true),
() => app.options.setValue('excludeNotExported', false)
() => app.options.setValue('excludeNotExported', true).unwrap(),
() => app.options.setValue('excludeNotExported', false).unwrap()
],
['specs-with-lump-categories',
() => app.options.setValue('categorizeByGroup', false),
() => app.options.setValue('categorizeByGroup', true)
() => app.options.setValue('categorizeByGroup', false).unwrap(),
() => app.options.setValue('categorizeByGroup', true).unwrap()
]
];

Expand Down
14 changes: 7 additions & 7 deletions src/test/typedoc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ describe('TypeDoc', function() {
});
it('honors the exclude argument even on a fixed directory list', function() {
const inputFiles = Path.join(__dirname, 'converter', 'class');
application.options.setValue('exclude', '**/class.ts');
application.options.setValue('exclude', '**/class.ts').unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert(!expanded.includes(Path.join(inputFiles, 'class.ts')));
Assert(!expanded.includes(inputFiles));
});
it('honors the exclude argument even on a fixed file list', function() {
const inputFiles = Path.join(__dirname, 'converter', 'class', 'class.ts');
application.options.setValue('exclude', '**/class.ts');
application.options.setValue('exclude', '**/class.ts').unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert(!expanded.includes(inputFiles));
});
it('supports multiple excludes', function() {
const inputFiles = Path.join(__dirname, 'converter');
application.options.setValue('exclude', '**/+(class|access).ts');
application.options.setValue('exclude', '**/+(class|access).ts').unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts')));
Expand All @@ -49,7 +49,7 @@ describe('TypeDoc', function() {
});
it('supports array of excludes', function() {
const inputFiles = Path.join(__dirname, 'converter');
application.options.setValue('exclude', [ '**/class.ts', '**/access.ts' ]);
application.options.setValue('exclude', [ '**/class.ts', '**/access.ts' ]).unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert(!expanded.includes(Path.join(inputFiles, 'class', 'class.ts')));
Expand All @@ -58,7 +58,7 @@ describe('TypeDoc', function() {
});
it('supports excluding directories beginning with dots', function() {
const inputFiles = __dirname;
application.options.setValue('exclude', '**/+(.dot)/**');
application.options.setValue('exclude', '**/+(.dot)/**').unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert(!expanded.includes(Path.join(inputFiles, '.dot', 'index.ts')));
Expand All @@ -79,7 +79,7 @@ describe('TypeDoc', function() {

it('supports directory excludes', function() {
const inputFiles = Path.join(__dirname, 'converter');
application.options.setValue('exclude', [ '**/alias' ]);
application.options.setValue('exclude', [ '**/alias' ]).unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'class', 'class.ts')), true);
Expand All @@ -89,7 +89,7 @@ describe('TypeDoc', function() {

it('supports negations in directory excludes', function() {
const inputFiles = Path.join(__dirname, 'converter');
application.options.setValue('exclude', [ '**/!(alias)/' ]);
application.options.setValue('exclude', [ '**/!(alias)/' ]).unwrap();
const expanded = application.expandInputFiles([inputFiles]);

Assert.strictEqual(expanded.includes(Path.join(inputFiles, 'class', 'class.ts')), false);
Expand Down

0 comments on commit a2e4db1

Please sign in to comment.