Skip to content

Commit a2e4db1

Browse files
committed
fix: Report errors from setting bad options on CLI
Closes #1237
1 parent 508f8ba commit a2e4db1

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

src/lib/utils/options/readers/arguments.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class ArgumentsReader implements OptionsReader {
1919
const seen = new Set<string>();
2020
let index = 0;
2121

22+
const error = (error: Error) => logger.error(error.message);
23+
2224
while (index < this.args.length) {
2325
const name = this.args[index];
2426
const decl = name.startsWith('-')
@@ -30,19 +32,19 @@ export class ArgumentsReader implements OptionsReader {
3032
container.setValue(
3133
decl.name,
3234
(container.getValue(decl.name) as string[]).concat(this.args[index])
33-
);
35+
).mapErr(error);
3436
} else if (decl.type === ParameterType.Boolean) {
3537
const value = String(this.args[index]).toLowerCase();
3638

3739
if (value === 'true' || value === 'false') {
38-
container.setValue(decl.name, value === 'true');
40+
container.setValue(decl.name, value === 'true').mapErr(error);
3941
} else {
40-
container.setValue(decl.name, true);
42+
container.setValue(decl.name, true).mapErr(error);
4143
// Bool option didn't consume the next argument as expected.
4244
index--;
4345
}
4446
} else {
45-
container.setValue(decl.name, this.args[index]);
47+
container.setValue(decl.name, this.args[index]).mapErr(error);
4648
}
4749
seen.add(decl.name);
4850
} else {

src/test/converter.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ describe('Converter', function() {
2626
const checks: [string, () => void, () => void][] = [
2727
['specs', () => { }, () => { }],
2828
['specs.d',
29-
() => app.options.setValue('includeDeclarations', true),
30-
() => app.options.setValue('includeDeclarations', false)
29+
() => app.options.setValue('includeDeclarations', true).unwrap(),
30+
() => app.options.setValue('includeDeclarations', false).unwrap()
3131
],
3232
['specs-without-exported',
33-
() => app.options.setValue('excludeNotExported', true),
34-
() => app.options.setValue('excludeNotExported', false)
33+
() => app.options.setValue('excludeNotExported', true).unwrap(),
34+
() => app.options.setValue('excludeNotExported', false).unwrap()
3535
],
3636
['specs-with-lump-categories',
37-
() => app.options.setValue('categorizeByGroup', false),
38-
() => app.options.setValue('categorizeByGroup', true)
37+
() => app.options.setValue('categorizeByGroup', false).unwrap(),
38+
() => app.options.setValue('categorizeByGroup', true).unwrap()
3939
]
4040
];
4141

src/test/typedoc.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ describe('TypeDoc', function() {
2525
});
2626
it('honors the exclude argument even on a fixed directory list', function() {
2727
const inputFiles = Path.join(__dirname, 'converter', 'class');
28-
application.options.setValue('exclude', '**/class.ts');
28+
application.options.setValue('exclude', '**/class.ts').unwrap();
2929
const expanded = application.expandInputFiles([inputFiles]);
3030

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)