Add ignoreFlags option to cli-flags
MODIFY
packages/@romejs/cli-flags/Parser.ts
packages/@romejs/cli-flags/Parser.ts
@@ -31,6 +31,7 @@ type CommandOptions<T extends Dict<unknown>> = {
description?: string;
usage?: string;
examples?: Examples;
+ ignoreFlags?: Array<string>;
defineFlags?: (consumer: Consumer) => T;
callback: (flags: T) => void | Promise<void>;
};
@@ -54,6 +55,7 @@ export type ParserOptions<T> = {
usage?: string;
description?: string;
version?: string;
+ ignoreFlags?: Array<string>;
defineFlags: (consumer: Consumer) => T;
};
@@ -72,7 +74,6 @@ export default class Parser<T> {
this.shorthandFlags = new Set();
this.incorrectCaseFlags = new Set();
-
this.declaredFlags = new Map();
this.defaultFlags = new Map();
this.flags = new Map();
@@ -335,18 +336,23 @@ export default class Parser<T> {
return await this.defineCommandFlags(commandName, consumer);
}
- async init(): Promise<T> {
- // Show help for --version
- if (this.flags.has('version')) {
- this.reporter.logAll(`v${String(this.opts.version)}`);
- process.exit(0);
+ checkBadFlags(consumer: Consumer, definedCommand: undefined | DefinedCommand) {
+ if (this.helpMode) {
+ return;
}
- const consumer = this.getFlagsConsumer();
-
- let definedCommand: undefined | DefinedCommand;
+ // Ignore flags from command and root parser options
+ const ignoreFlags: Array<string> = [
+ ...(definedCommand !== undefined && definedCommand.command.ignoreFlags ||
+ []),
+ ...(this.opts.ignoreFlags || []),
+ ];
+ for (const key of ignoreFlags) {
+ this.shorthandFlags.delete(key);
+ this.incorrectCaseFlags.delete(key);
+ consumer.markUsedProperty(key);
+ }
- const rootFlags = await consumer.bufferDiagnostics(async (consumer) => {
for (const shorthandName of this.shorthandFlags) {
consumer.get(shorthandName).unexpected(
descriptions.FLAGS.UNSUPPORTED_SHORTHANDS,
@@ -359,6 +365,21 @@ export default class Parser<T> {
);
}
+ consumer.enforceUsedProperties('flag', false);
+ }
+
+ async init(): Promise<T> {
+ // Show help for --version
+ if (this.flags.has('version')) {
+ this.reporter.logAll(String(this.opts.version));
+ process.exit(0);
+ }
+
+ const consumer = this.getFlagsConsumer();
+
+ let definedCommand: undefined | DefinedCommand;
+
+ const rootFlags = await consumer.bufferDiagnostics(async (consumer) => {
const rootFlags = this.opts.defineFlags(consumer);
for (const key of this.commands.keys()) {
@@ -370,9 +391,7 @@ export default class Parser<T> {
}
}
- if (!this.helpMode) {
- consumer.enforceUsedProperties('flag', false);
- }
+ this.checkBadFlags(consumer, definedCommand);
this.currentCommand = undefined;
return rootFlags;
@@ -463,7 +482,7 @@ export default class Parser<T> {
// Output options
for (const {arg, description} of optionOutput) {
lines.push(
- markup`<dim><pad count="${argColumnLength}" dir="right">${arg}</pad></dim> ${description}`,
+ markup`<brightBlack><pad count="${argColumnLength}" dir="right">${arg}</pad></brightBlack> ${description}`,
);
}

MODIFY
packages/@romejs/cli/cli.ts
packages/@romejs/cli/cli.ts
@@ -162,6 +162,7 @@ export default async function cli() {
category: local.category,
description: local.description,
defineFlags: local.defineFlags,
+ ignoreFlags: local.ignoreFlags,
examples: local.examples,
usage: local.usage,
callback(_commandFlags) {
@@ -180,6 +181,7 @@ export default async function cli() {
category: master.category,
description: master.description,
defineFlags: master.defineFlags,
+ ignoreFlags: master.ignoreFlags,
usage: master.usage,
examples: master.examples,

MODIFY
packages/@romejs/core/client/commands/lsp.ts
packages/@romejs/core/client/commands/lsp.ts
import {commandCategories} from '../../common/commands';
import {createLocalCommand} from '../commands';
import ClientRequest from '../ClientRequest';
-import {Consumer} from '@romejs/consume';
export default createLocalCommand({
description: 'connect to an lsp',
@@ -16,10 +15,10 @@ export default createLocalCommand({
usage: '',
examples: [],
- defineFlags(consumer: Consumer) {
// vscode-languageclient adds these on
- consumer.get('stdio').asBooleanOrVoid();
- consumer.get('clientProcessId').asStringOrVoid();
+ ignoreFlags: ['stdio', 'clientProcessId'],
+
+ defineFlags() {
return {};
},

MODIFY
packages/@romejs/core/common/commands.ts
packages/@romejs/core/common/commands.ts
@@ -17,6 +17,7 @@ export type SharedCommand<Flags extends Dict<unknown>> = {
description: string;
command: string;
}>;
+ ignoreFlags?: Array<string>;
allowRequestFlags?: Array<'review' | 'watch' | 'allowDirty'>;
};

Add ignoreFlags option to cli-flags