Skip to content

Commit

Permalink
Feature: allow reporting with no input when not writing ROMs (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm committed May 8, 2024
1 parent 4ee0d8c commit 57d166d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,17 @@ export default class ArgumentsParser {
group: groupRomInput,
alias: 'i',
description: 'Path(s) to ROM files or archives (supports globbing)',
demandOption: true,
type: 'array',
requiresArg: true,
})
.check((checkArgv) => {
const needInput = ['copy', 'move', 'link', 'symlink', 'extract', 'zip', 'test', 'dir2dat', 'fixdat'].filter((command) => checkArgv._.includes(command));
if (!checkArgv.input && needInput.length > 0) {
// TODO(cememr): print help message
throw new Error(`Missing required argument for command${needInput.length !== 1 ? 's' : ''} ${needInput.join(', ')}: --input <path>`);
}
return true;
})
.option('input-exclude', {
group: groupRomInput,
alias: 'I',
Expand Down Expand Up @@ -280,7 +287,7 @@ export default class ArgumentsParser {
}
const needDat = ['report'].filter((command) => checkArgv._.includes(command));
if ((!checkArgv.dat || checkArgv.dat.length === 0) && needDat.length > 0) {
throw new Error(`Missing required option for commands ${needDat.join(', ')}: --dat`);
throw new Error(`Missing required argument for commands ${needDat.join(', ')}: --dat`);
}
return true;
})
Expand Down Expand Up @@ -408,10 +415,10 @@ export default class ArgumentsParser {
if (checkArgv.help) {
return true;
}
const needOutput = ['copy', 'move', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command));
const needOutput = ['copy', 'move', 'link', 'symlink', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command));
if (!checkArgv.output && needOutput.length > 0) {
// TODO(cememr): print help message
throw new Error(`Missing required option for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output <path>`);
throw new Error(`Missing required argument for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output <path>`);
}
const needClean = ['clean-exclude', 'clean-dry-run'].filter((option) => checkArgv[option]);
if (!checkArgv._.includes('clean') && needClean.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/candidateGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class CandidateGenerator extends Module {
): Promise<Map<Parent, ReleaseCandidate[]>> {
if (indexedFiles.getFiles().length === 0) {
this.progressBar.logTrace(`${dat.getNameShort()}: no input ROMs to make candidates from`);
return new Map();
return new Map(dat.getParents().map((parent) => ([parent, []])));
}

const output = new Map<Parent, ReleaseCandidate[]>();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/reportGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export default class ReportGenerator extends Module {

const reportPath = this.options.getReportOutput();

const anyGamesFoundAtAll = datStatuses
.some((datStatus) => datStatus.anyGamesFound(this.options));
const matchedFileCsvs = (await Promise.all(
datStatuses
.filter((datStatus) => datStatus.anyGamesFound(this.options))
.filter((datStatus) => datStatus.anyGamesFound(this.options) || !anyGamesFoundAtAll)
.sort((a, b) => a.getDATName().localeCompare(b.getDATName()))
.map(async (datsStatus) => datsStatus.toCsv(this.options)),
))
Expand Down
2 changes: 1 addition & 1 deletion src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export default class Options implements OptionsProps {
}

private async scanInputFiles(walkCallback?: FsWalkCallback): Promise<string[]> {
return Options.scanPaths(this.input, walkCallback);
return Options.scanPaths(this.input, walkCallback, this.shouldWrite() || !this.shouldReport());
}

private async scanInputExcludeFiles(): Promise<string[]> {
Expand Down
20 changes: 15 additions & 5 deletions test/modules/argumentsParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ describe('options', () => {
});

it('should parse "input"', async () => {
expect(() => argumentsParser.parse(['copy', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['move', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['link', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', 'extract', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', 'zip', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', 'test', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['dir2dat', '--output', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['fixdat', '--output', os.devNull])).toThrow(/missing required argument/i);
await expect(argumentsParser.parse(['copy', '--input', 'nonexistentfile', '--output', os.devNull]).scanInputFilesWithoutExclusions()).rejects.toThrow(/no files found/i);
await expect(argumentsParser.parse(['copy', '--input', os.devNull, '--output', os.devNull]).scanInputFilesWithoutExclusions()).resolves.toHaveLength(0);

Expand Down Expand Up @@ -232,7 +240,7 @@ describe('options', () => {
});

it('should parse "dat"', async () => {
expect(() => argumentsParser.parse(['report', '--input', os.devNull])).toThrow(/missing required option/i);
expect(() => argumentsParser.parse(['report', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse([...dummyCommandAndRequiredArgs, '--dat'])).toThrow(/not enough arguments/i);
await expect(argumentsParser.parse(dummyCommandAndRequiredArgs).scanDatFilesWithoutExclusions())
.resolves.toHaveLength(0);
Expand Down Expand Up @@ -391,10 +399,12 @@ describe('options', () => {
it('should parse "output"', () => {
// Test requirements per command
expect(() => argumentsParser.parse(['test'])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', '--input', os.devNull])).toThrow(/missing required option/i);
expect(() => argumentsParser.parse(['move', '--input', os.devNull])).toThrow(/missing required option/i);
expect(() => argumentsParser.parse(['copy', 'zip', '--input', os.devNull])).toThrow(/missing required option/i);
expect(() => argumentsParser.parse(['copy', 'clean', '--input', os.devNull])).toThrow(/missing required option/i);
expect(() => argumentsParser.parse(['copy', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['move', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['link', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', 'extract', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', 'zip', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(() => argumentsParser.parse(['copy', 'clean', '--input', os.devNull])).toThrow(/missing required argument/i);
expect(argumentsParser.parse(['report', '--dat', os.devNull, '--input', os.devNull]).getOutput()).toContain(Constants.GLOBAL_TEMP_DIR);
// Test value
expect(argumentsParser.parse(['copy', '--input', os.devNull, '-o', 'foo']).getOutput()).toEqual('foo');
Expand Down
5 changes: 4 additions & 1 deletion test/modules/candidateGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ describe.each(['zip', 'extract', 'raw'])('command: %s', (command) => {
const parentsToCandidates = await candidateGenerator(options, datWithGamesWithNoRoms, []);

// Then
expect(parentsToCandidates.size).toEqual(0);
expect(parentsToCandidates.size).toEqual(1);
const totalReleaseCandidates = [...parentsToCandidates.values()]
.reduce((sum, releaseCandidates) => sum + releaseCandidates.length, 0);
expect(totalReleaseCandidates).toEqual(0);
});

test.each([
Expand Down

0 comments on commit 57d166d

Please sign in to comment.