Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: breaking: remove deprecated options #1036

Merged
merged 4 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 22 additions & 107 deletions src/modules/argumentsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ export default class ArgumentsParser {

// Add every command to a yargs object, recursively, resulting in the ability to specify
// multiple commands
const commands: [string, string | boolean][] = [
const commands = [
['copy', 'Copy ROM files from the input to output directory'],
['move', 'Move ROM files from the input to output directory'],
['link', 'Create links in the output directory to ROM files in the input directory'],
['symlink', false],
['extract', 'Extract ROM files in archives when copying or moving'],
['zip', 'Create zip archives of ROMs when copying or moving'],
['test', 'Test ROMs for accuracy after writing them to the output directory'],
Expand All @@ -102,9 +101,9 @@ export default class ArgumentsParser {
];
const mutuallyExclusiveCommands = [
// Write commands
['copy', 'move', 'link', 'symlink'],
['copy', 'move', 'link'],
// Archive manipulation commands
['link', 'symlink', 'extract', 'zip'],
['link', 'extract', 'zip'],
// DAT writing commands
['dir2dat', 'fixdat'],
];
Expand All @@ -124,18 +123,10 @@ export default class ArgumentsParser {
return !incompatibleCommands.includes(command);
})
.forEach(([command, description]) => {
if (typeof description === 'string') {
yargsObj.command(command, description, (yargsSubObj) => addCommands(
yargsSubObj,
[...previousCommands, command],
));
} else {
// A deprecation message should be printed elsewhere
yargsObj.command(command, false, (yargsSubObj) => addCommands(
yargsSubObj,
[...previousCommands, command],
));
}
yargsObj.command(command, description, (yargsSubObj) => addCommands(
yargsSubObj,
[...previousCommands, command],
));
});

if (previousCommands.length === 0) {
Expand All @@ -160,7 +151,7 @@ export default class ArgumentsParser {
});

['test', 'clean'].forEach((command) => {
if (checkArgv._.includes(command) && ['copy', 'move', 'link', 'symlink'].every((write) => !checkArgv._.includes(write))) {
if (checkArgv._.includes(command) && ['copy', 'move', 'link'].every((write) => !checkArgv._.includes(write))) {
throw new ExpectedError(`Command "${command}" requires one of the commands: copy, move, or link`);
}
});
Expand Down Expand Up @@ -192,7 +183,7 @@ export default class ArgumentsParser {
requiresArg: true,
})
.check((checkArgv) => {
const needInput = ['copy', 'move', 'link', 'symlink', 'extract', 'zip', 'test', 'dir2dat', 'fixdat'].filter((command) => checkArgv._.includes(command));
const needInput = ['copy', 'move', 'link', 'extract', 'zip', 'test', 'dir2dat', 'fixdat'].filter((command) => checkArgv._.includes(command));
if (!checkArgv.input && needInput.length > 0) {
// TODO(cememr): print help message
throw new ExpectedError(`Missing required argument for command${needInput.length !== 1 ? 's' : ''} ${needInput.join(', ')}: --input <path>`);
Expand Down Expand Up @@ -257,31 +248,13 @@ export default class ArgumentsParser {
coerce: ArgumentsParser.readRegexFile,
requiresArg: true,
})
.option('dat-regex', {
type: 'string',
coerce: (val) => {
this.logger.warn('the \'--dat-regex\' option is deprecated, use \'--dat-name-regex\' instead');
return ArgumentsParser.readRegexFile(val);
},
requiresArg: true,
hidden: true,
})
.option('dat-name-regex-exclude', {
group: groupDatInput,
description: 'Regular expression of DAT names to exclude from processing',
type: 'string',
coerce: ArgumentsParser.readRegexFile,
requiresArg: true,
})
.option('dat-regex-exclude', {
type: 'string',
coerce: (val) => {
this.logger.warn('the \'--dat-regex-exclude\' option is deprecated, use \'--dat-name-regex-exclude\' instead');
return ArgumentsParser.readRegexFile(val);
},
requiresArg: true,
hidden: true,
})
.option('dat-description-regex', {
group: groupDatInput,
description: 'Regular expression of DAT descriptions to process',
Expand Down Expand Up @@ -333,17 +306,6 @@ export default class ArgumentsParser {
requiresArg: true,
})

.option('fixdat', {
type: 'boolean',
coerce: (val: boolean) => {
this.logger.warn('the \'--fixdat\' option is deprecated, use the \'fixdat\' command instead');
return val;
},
implies: 'dat',
deprecated: true,
hidden: true,
})

.option('output', {
group: groupRomOutputPath,
alias: 'o',
Expand Down Expand Up @@ -440,7 +402,7 @@ export default class ArgumentsParser {
if (checkArgv.help) {
return true;
}
const needOutput = ['copy', 'move', 'link', 'symlink', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command));
const needOutput = ['copy', 'move', 'link', 'extract', 'zip', 'clean'].filter((command) => checkArgv._.includes(command));
if (!checkArgv.output && needOutput.length > 0) {
// TODO(cememr): print help message
throw new ExpectedError(`Missing required argument for command${needOutput.length !== 1 ? 's' : ''} ${needOutput.join(', ')}: --output <path>`);
Expand Down Expand Up @@ -508,15 +470,6 @@ export default class ArgumentsParser {
description: 'Creates symbolic links instead of hard links',
type: 'boolean',
})
.middleware((middlewareArgv) => {
if (middlewareArgv._.includes('symlink')) {
this.logger.warn('the \'symlink\' command is deprecated, use \'link --symlink\' instead');
if (middlewareArgv.symlink === undefined) {
// eslint-disable-next-line no-param-reassign
middlewareArgv.symlink = true;
}
}
}, true)
.option('symlink-relative', {
group: groupRomLink,
description: 'Create symlinks as relative to the target path, as opposed to absolute',
Expand All @@ -528,7 +481,7 @@ export default class ArgumentsParser {
return true;
}
const needLinkCommand = ['symlink'].filter((option) => checkArgv[option]);
if (!checkArgv._.includes('link') && !checkArgv._.includes('symlink') && needLinkCommand.length > 0) {
if (!checkArgv._.includes('link') && needLinkCommand.length > 0) {
throw new ExpectedError(`Missing required command for option${needLinkCommand.length !== 1 ? 's' : ''} ${needLinkCommand.join(', ')}: link`);
}
return true;
Expand Down Expand Up @@ -609,16 +562,6 @@ export default class ArgumentsParser {
}
return true;
})
.option('language-filter', {
type: 'string',
coerce: (val: string) => {
this.logger.warn('the \'--language-filter\' option is deprecated, use \'--filter-language\' instead');
return val.split(',');
},
requiresArg: true,
deprecated: true,
hidden: true,
})
.option('filter-region', {
group: groupRomFiltering,
alias: 'R',
Expand All @@ -633,16 +576,6 @@ export default class ArgumentsParser {
throw new ExpectedError(`Invalid --filter-region region${invalidRegions.length !== 1 ? 's' : ''}: ${invalidRegions.join(', ')}`);
}
return true;
})
.option('region-filter', {
type: 'string',
coerce: (val: string) => {
this.logger.warn('the \'--region-filter\' option is deprecated, use \'--filter-region\' instead');
return val.split(',');
},
requiresArg: true,
deprecated: true,
hidden: true,
});
[
['bios', 'BIOS files'],
Expand All @@ -669,48 +602,30 @@ export default class ArgumentsParser {
type: 'boolean',
});
([
['debug', 'debug ROMs', false],
['demo', 'demo ROMs', false],
['beta', 'beta ROMs', false],
['sample', 'sample ROMs', false],
['prototype', 'prototype ROMs', false],
['test-roms', 'test ROMs', true],
['program', 'program application ROMs', false],
['aftermarket', 'aftermarket ROMs', false],
['homebrew', 'homebrew ROMs', false],
['unverified', 'unverified ROMs', false],
['bad', 'bad ROM dumps', false],
] satisfies [string, string, boolean][]).forEach(([key, description, hidden]) => {
['debug', 'debug ROMs'],
['demo', 'demo ROMs'],
['beta', 'beta ROMs'],
['sample', 'sample ROMs'],
['prototype', 'prototype ROMs'],
['program', 'program application ROMs'],
['aftermarket', 'aftermarket ROMs'],
['homebrew', 'homebrew ROMs'],
['unverified', 'unverified ROMs'],
['bad', 'bad ROM dumps'],
]).forEach(([key, description]) => {
yargsParser
.option(`no-${key}`, {
group: groupRomFiltering,
description: `Filter out ${description}, opposite of --only-${key}`,
type: 'boolean',
conflicts: [`only-${key}`],
hidden,
})
.option(`only-${key}`, {
type: 'boolean',
conflicts: [`no-${key}`],
hidden: true,
});
});
yargsParser.middleware((middlewareArgv) => {
if (middlewareArgv['no-test-roms'] === true) {
this.logger.warn('the \'--no-test-roms\' option is deprecated, use \'--no-program\' instead');
if (middlewareArgv.noProgram === undefined) {
// eslint-disable-next-line no-param-reassign
middlewareArgv.noProgram = true;
}
}
if (middlewareArgv['only-test-roms'] === true) {
this.logger.warn('the \'--only-test-roms\' option is deprecated, use \'--only-program\' instead');
if (middlewareArgv.onlyProgram === undefined) {
// eslint-disable-next-line no-param-reassign
middlewareArgv.onlyProgram = true;
}
}
}, true);

yargsParser
.option('single', {
Expand Down
34 changes: 4 additions & 30 deletions src/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export enum FixExtension {

export interface OptionsProps {
readonly commands?: string[],
readonly fixdat?: boolean;

readonly input?: string[],
readonly inputExclude?: string[],
Expand All @@ -69,9 +68,7 @@ export interface OptionsProps {

readonly dat?: string[],
readonly datExclude?: string[],
readonly datRegex?: string,
readonly datNameRegex?: string,
readonly datRegexExclude?: string,
readonly datNameRegexExclude?: string,
readonly datDescriptionRegex?: string,
readonly datDescriptionRegexExclude?: string,
Expand Down Expand Up @@ -114,9 +111,7 @@ export interface OptionsProps {
readonly filterRegex?: string,
readonly filterRegexExclude?: string,
readonly filterLanguage?: string[],
readonly languageFilter?: string[],
readonly filterRegion?: string[],
readonly regionFilter?: string[],
readonly noBios?: boolean,
readonly onlyBios?: boolean,
readonly noDevice?: boolean,
Expand Down Expand Up @@ -179,8 +174,6 @@ export default class Options implements OptionsProps {
@Expose({ name: '_' })
readonly commands: string[];

readonly fixdat: boolean;

readonly input: string[];

readonly inputExclude: string[];
Expand All @@ -193,12 +186,8 @@ export default class Options implements OptionsProps {

readonly datExclude: string[];

readonly datRegex: string;

readonly datNameRegex: string;

readonly datRegexExclude: string;

readonly datNameRegexExclude: string;

readonly datDescriptionRegex: string;
Expand Down Expand Up @@ -267,12 +256,8 @@ export default class Options implements OptionsProps {

readonly filterLanguage: string[];

readonly languageFilter: string[];

readonly filterRegion: string[];

readonly regionFilter: string[];

readonly noBios: boolean;

readonly onlyBios: boolean;
Expand Down Expand Up @@ -379,7 +364,6 @@ export default class Options implements OptionsProps {

constructor(options?: OptionsProps) {
this.commands = options?.commands ?? [];
this.fixdat = options?.fixdat ?? false;

this.input = options?.input ?? [];
this.inputExclude = options?.inputExclude ?? [];
Expand All @@ -388,9 +372,7 @@ export default class Options implements OptionsProps {

this.dat = options?.dat ?? [];
this.datExclude = options?.datExclude ?? [];
this.datRegex = options?.datRegex ?? '';
this.datNameRegex = options?.datNameRegex ?? '';
this.datRegexExclude = options?.datRegexExclude ?? '';
this.datNameRegexExclude = options?.datNameRegexExclude ?? '';
this.datDescriptionRegex = options?.datDescriptionRegex ?? '';
this.datDescriptionRegexExclude = options?.datDescriptionRegexExclude ?? '';
Expand Down Expand Up @@ -432,9 +414,7 @@ export default class Options implements OptionsProps {
this.filterRegex = options?.filterRegex ?? '';
this.filterRegexExclude = options?.filterRegexExclude ?? '';
this.filterLanguage = options?.filterLanguage ?? [];
this.languageFilter = options?.languageFilter ?? [];
this.filterRegion = options?.filterRegion ?? [];
this.regionFilter = options?.regionFilter ?? [];
this.noBios = options?.noBios ?? false;
this.onlyBios = options?.onlyBios ?? false;
this.noDevice = options?.noDevice ?? false;
Expand Down Expand Up @@ -542,7 +522,7 @@ export default class Options implements OptionsProps {
* The writing command that was specified.
*/
writeString(): string | undefined {
return ['copy', 'move', 'link', 'symlink'].find((command) => this.getCommands().has(command));
return ['copy', 'move', 'link'].find((command) => this.getCommands().has(command));
}

/**
Expand Down Expand Up @@ -602,7 +582,7 @@ export default class Options implements OptionsProps {
* Was the 'fixdat' command provided?
*/
shouldFixdat(): boolean {
return this.getCommands().has('fixdat') || this.fixdat;
return this.getCommands().has('fixdat');
}

/**
Expand Down Expand Up @@ -813,11 +793,11 @@ export default class Options implements OptionsProps {
}

getDatNameRegex(): RegExp[] | undefined {
return Options.getRegex(this.datNameRegex || this.datRegex);
return Options.getRegex(this.datNameRegex);
}

getDatNameRegexExclude(): RegExp[] | undefined {
return Options.getRegex(this.datNameRegexExclude || this.datRegexExclude);
return Options.getRegex(this.datNameRegexExclude);
}

getDatDescriptionRegex(): RegExp[] | undefined {
Expand Down Expand Up @@ -1050,19 +1030,13 @@ export default class Options implements OptionsProps {
if (this.filterLanguage.length > 0) {
return new Set(Options.filterUniqueUpper(this.filterLanguage));
}
if (this.languageFilter.length > 0) {
return new Set(Options.filterUniqueUpper(this.languageFilter));
}
return new Set();
}

getFilterRegion(): Set<string> {
if (this.filterRegion.length > 0) {
return new Set(Options.filterUniqueUpper(this.filterRegion));
}
if (this.regionFilter.length > 0) {
return new Set(Options.filterUniqueUpper(this.regionFilter));
}
return new Set();
}

Expand Down
Loading
Loading