Add CLI global flag descriptions
MODIFY
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
packages/@romejs/cli-diagnostics/DiagnosticsPrinter.ts
@@ -13,7 +13,6 @@ import {
Diagnostics,
DiagnosticsProcessor,
deriveRootAdviceFromDiagnostic,
- getDiagnosticHeader,
} from '@romejs/diagnostics';
import {Reporter} from '@romejs/cli-reporter';
import {
@@ -23,11 +22,7 @@ import {
DiagnosticsPrinterOptions,
} from './types';
-import {
- formatAnsi,
- humanizeMarkupFilename,
- markup,
-} from '@romejs/string-markup';
+import {formatAnsi, markup, markupToPlainText} from '@romejs/string-markup';
import {toLines} from './utils';
import printAdvice from './printAdvice';
@@ -89,7 +84,6 @@ type BeforeFooterPrintFn = (reporter: Reporter, error: boolean) => void;
export const DEFAULT_PRINTER_FLAGS: DiagnosticsPrinterFlags = {
grep: '',
inverseGrep: false,
- focus: '',
showAllDiagnostics: true,
fieri: false,
verboseDiagnostics: false,
@@ -208,43 +202,8 @@ export default class DiagnosticsPrinter extends Error {
return this.processor.getSortedDiagnostics();
}
- isFocused(diag: Diagnostic): boolean {
- const focusFlag = this.flags.focus;
- const focusEnabled = focusFlag !== undefined && focusFlag !== '';
-
- const {filename, start, end} = diag.location;
-
- // If focus is enabled, exclude locationless errors
- if (focusEnabled && (filename === undefined || start === undefined)) {
- return true;
- }
-
- // If focus is enabled, check if we should ignore this message
- if (filename !== undefined && start !== undefined && end !== undefined) {
- const niceFilename = humanizeMarkupFilename(
- filename,
- this.reporter.markupOptions,
- );
- const focusId = getDiagnosticHeader({
- filename,
- start,
- });
- if (focusEnabled && focusId !== focusFlag && focusId !== niceFilename) {
- return true;
- }
- }
-
- return false;
- }
-
shouldIgnore(diag: Diagnostic): boolean {
- const {focus, grep, inverseGrep} = this.flags;
- const focusEnabled = focus !== undefined && focus !== '';
-
- // If focus is enabled, exclude locationless errors
- if (focusEnabled && this.isFocused(diag) === false) {
- return true;
- }
+ const {grep, inverseGrep} = this.flags;
// An empty grep pattern means show everything
if (grep === undefined || grep === '') {
@@ -253,7 +212,9 @@ export default class DiagnosticsPrinter extends Error {
// Match against the supplied grep pattern
let ignored =
- diag.description.message.value.toLowerCase().includes(grep) === false;
+ markupToPlainText(diag.description.message.value).toLowerCase().includes(
+ grep,
+ ) === false;
if (inverseGrep) {
ignored = !ignored;
}

MODIFY
packages/@romejs/cli-diagnostics/types.ts
packages/@romejs/cli-diagnostics/types.ts
@@ -13,7 +13,6 @@ export type DiagnosticsPrinterFlags = {
grep: string;
fieri: boolean;
inverseGrep: boolean;
- focus: string;
verboseDiagnostics: boolean;
maxDiagnostics: number;
showAllDiagnostics: boolean;

MODIFY
packages/@romejs/cli-flags/Parser.ts
packages/@romejs/cli-flags/Parser.ts
@@ -473,7 +473,18 @@ export default class Parser<T> {
}
}
- argCol += ` <${inputName}>`;
+ argCol += ` <${inputName}`;
+
+ const defaultValue = def.default;
+ if (
+ !def.required &&
+ defaultValue !== undefined &&
+ (typeof defaultValue === 'number' || typeof defaultValue === 'string')
+ ) {
+ argCol += `=${defaultValue}`;
+ }
+
+ argCol += '>';
}
// Set arg col length if we'll be longer

MODIFY
packages/@romejs/cli/cli.ts
packages/@romejs/cli/cli.ts
@@ -18,11 +18,7 @@ import {
} from '@romejs/core';
import setProcessTitle from './utils/setProcessTitle';
import {parseCLIFlagsFromProcess} from '@romejs/cli-flags';
-import {
- UnknownFilePath,
- createAbsoluteFilePath,
- maybeCreateAbsoluteFilePath,
-} from '@romejs/path';
+import {UnknownFilePath, createAbsoluteFilePath} from '@romejs/path';
import {Consumer} from '@romejs/consume';
import {
ClientProfileOptions,
@@ -63,72 +59,200 @@ export default async function cli() {
clientFlags: ClientFlags;
requestFlags: ClientRequestFlags;
} {
+ // We need this to resolve other flags relative to
+ // We do the word `void ||` nonsense to avoid setting a default flag value
+ const cwd =
+ c.get(
+ 'cwd',
+ {
+ description: 'Specify a different working directory',
+ },
+ ).asAbsoluteFilePathOrVoid() || createAbsoluteFilePath(process.cwd());
+
return {
clientFlags: {
clientName: 'cli',
- cwd: createAbsoluteFilePath(c.get('cwd').asString(process.cwd())),
- verbose: c.get('verbose').asBoolean(DEFAULT_CLIENT_FLAGS.verbose),
- silent: c.get('silent').asBoolean(DEFAULT_CLIENT_FLAGS.silent),
+ cwd,
+ verbose: c.get(
+ 'verbose',
+ {
+ description: 'Output verbose logs',
+ },
+ ).asBoolean(DEFAULT_CLIENT_FLAGS.verbose),
+ silent: c.get(
+ 'silent',
+ {
+ description: "Don't write anything to the console",
+ },
+ ).asBoolean(DEFAULT_CLIENT_FLAGS.silent),
...overrideClientFlags,
},
cliFlags: {
- markersPath: maybeCreateAbsoluteFilePath(
- c.get('markersPath').asStringOrVoid(),
- ),
- profile: c.get('profile').asBoolean(false),
- profilePath: maybeCreateAbsoluteFilePath(
- c.get('profilePath').asStringOrVoid(),
- ),
- profileTimeout: c.get('profileTimeout').asNumber(0),
- profileWorkers: c.get('profileWorkers').asBoolean(true),
- profileSampling: c.get('profileSampling').asNumber(100),
- temporaryDaemon: c.get('temporaryDaemon').asBoolean(false),
- rage: c.get('rage').asBoolean(false),
- ragePath: maybeCreateAbsoluteFilePath(
- c.get('ragePath').asStringOrVoid(),
- ),
- logs: c.get('logs').asBoolean(false),
- logWorkers: c.get('logWorkers').asBooleanOrVoid(),
- logPath: maybeCreateAbsoluteFilePath(
- c.get('logPath').asStringOrVoid(),
- ),
+ markersPath: c.get(
+ 'markersPath',
+ {
+ description: 'Path where to write markers. When ommitted defaults to Marker-TIMESTAMP.json',
+ },
+ ).asAbsoluteFilePathOrVoid(undefined, cwd),
+ profile: c.get(
+ 'profile',
+ {
+ description: 'Collect and write profile to disk. Includes profiles for all processes.',
+ },
+ ).asBoolean(false),
+ profilePath: c.get(
+ 'profilePath',
+ {
+ description: 'Path where to write profile. When omitted defaults to Profile-TIMESTAMP.json',
+ },
+ ).asAbsoluteFilePathOrVoid(undefined, cwd),
+ profileTimeout: c.get(
+ 'profileTimeout',
+ {
+ description: 'Stop the profile after the milliseconds specified. When omitted the profile is of the whole command',
+ },
+ ).asNumber(0),
+ profileWorkers: c.get(
+ 'profileWorkers',
+ {
+ description: 'Exclude workers from profile',
+ },
+ ).asBoolean(true),
+ profileSampling: c.get(
+ 'profileSampling',
+ {
+ description: 'Profiler sampling interval in microseconds',
+ },
+ ).asNumber(100),
+ temporaryDaemon: c.get(
+ 'temporaryDaemon',
+ {
+ description: "Start a daemon, if one isn't already running, for the lifetime of this command",
+ },
+ ).asBoolean(false),
+ rage: c.get(
+ 'rage',
+ {
+ description: 'Create a rage tarball of debug information',
+ },
+ ).asBoolean(false),
+ ragePath: c.get(
+ 'ragePath',
+ {
+ description: 'Path where to write rage tarball. When omitted defaults to Rage-TIMESTAMP.tgz',
+ },
+ ).asAbsoluteFilePathOrVoid(undefined, cwd),
+ logs: c.get(
+ 'logs',
+ {
+ description: 'Output master logs',
+ },
+ ).asBoolean(false),
+ logWorkers: c.get(
+ 'logWorkers',
+ {
+ description: 'Output worker logs',
+ },
+ ).asBooleanOrVoid(),
+ logPath: c.get(
+ 'logPath',
+ {
+ description: 'Path where to outpuit logs. When omitted logs are not written anywhere',
+ },
+ ).asAbsoluteFilePathOrVoid(undefined, cwd),
...overrideCLIFlags,
},
requestFlags: {
- benchmark: c.get('benchmark').asBoolean(
- DEFAULT_CLIENT_REQUEST_FLAGS.benchmark,
- ),
- benchmarkIterations: c.get('benchmarkIterations').asNumber(
- DEFAULT_CLIENT_REQUEST_FLAGS.benchmarkIterations,
- ),
- collectMarkers: c.get('collectMarkers').asBoolean(
- DEFAULT_CLIENT_REQUEST_FLAGS.collectMarkers,
- ),
- timing: c.get('timing').asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.timing),
- review: c.get('review').asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.review),
- watch: c.get('watch').asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.watch),
- fieri: c.get('fieri').asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.fieri),
- focus: c.get('focus').asString(DEFAULT_CLIENT_REQUEST_FLAGS.focus),
- grep: c.get('grep').asString(DEFAULT_CLIENT_REQUEST_FLAGS.grep),
- maxDiagnostics: c.get('maxDiagnostics').asNumber(
- DEFAULT_CLIENT_REQUEST_FLAGS.maxDiagnostics,
- ),
- verboseDiagnostics: c.get('verboseDiagnostics').asBoolean(
- DEFAULT_CLIENT_REQUEST_FLAGS.verboseDiagnostics,
- ),
- showAllDiagnostics: c.get('showAllDiagnostics').asBoolean(
- DEFAULT_CLIENT_REQUEST_FLAGS.showAllDiagnostics,
- ),
- inverseGrep: c.get('inverseGrep').asBoolean(
- DEFAULT_CLIENT_REQUEST_FLAGS.inverseGrep,
- ),
- resolverPlatform: c.get('resolverPlatform').asStringSetOrVoid(
- PLATFORMS,
- ),
- resolverScale: c.get('resolverScale').asNumberOrVoid(),
- resolverMocks: c.get('resolverMocks').asBoolean(
- DEFAULT_CLIENT_REQUEST_FLAGS.resolverMocks,
- ),
+ benchmark: c.get(
+ 'benchmark',
+ {
+ description: 'Run a command multiple times, calculating average',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.benchmark),
+ benchmarkIterations: c.get(
+ 'benchmarkIterations',
+ {
+ description: 'The amount of benchmark iterations to perform',
+ },
+ ).asNumber(DEFAULT_CLIENT_REQUEST_FLAGS.benchmarkIterations),
+ collectMarkers: c.get(
+ 'collectMarkers',
+ {
+ description: 'Collect and write performance markers to disk',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.collectMarkers),
+ timing: c.get(
+ 'timing',
+ {
+ description: 'Dump timing information after running the command',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.timing),
+ review: c.get(
+ 'review',
+ {
+ description: 'Display and perform actions on diagnostics. Only some commands support this.',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.review),
+ watch: c.get(
+ 'watch',
+ {
+ description: 'Keep running command and update on file changes. Only some commands support this.',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.watch),
+ fieri: c.get(
+ 'fieri',
+ {
+ description: 'Head to flavortown',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.fieri),
+ grep: c.get(
+ 'grep',
+ {
+ description: 'Only display diagnostics with messages containing this string',
+ },
+ ).asString(DEFAULT_CLIENT_REQUEST_FLAGS.grep),
+ inverseGrep: c.get(
+ 'inverseGrep',
+ {
+ description: 'Flip grep match. Only display diagnostics with messages that do NOT contain the grep string',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.inverseGrep),
+ maxDiagnostics: c.get(
+ 'maxDiagnostics',
+ {
+ description: 'Cap the amount of diagnostics displayed',
+ },
+ ).asNumber(DEFAULT_CLIENT_REQUEST_FLAGS.maxDiagnostics),
+ verboseDiagnostics: c.get(
+ 'verboseDiagnostics',
+ {
+ description: 'Display hidden and truncated diagnostic information',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.verboseDiagnostics),
+ showAllDiagnostics: c.get(
+ 'showAllDiagnostics',
+ {
+ description: 'Display all diagnostics ignoring caps',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.showAllDiagnostics),
+ resolverPlatform: c.get(
+ 'resolverPlatform',
+ {
+ description: 'Specify the platform for module resolution',
+ },
+ ).asStringSetOrVoid(PLATFORMS),
+ resolverScale: c.get(
+ 'resolverScale',
+ {
+ description: 'Specify the image scale for module resolution',
+ },
+ ).asNumberOrVoid(),
+ resolverMocks: c.get(
+ 'resolverMocks',
+ {
+ description: 'Enable mocks for module resolution',
+ },
+ ).asBoolean(DEFAULT_CLIENT_REQUEST_FLAGS.resolverMocks),
...overrideRequestFlags,
},
};
@@ -250,9 +374,7 @@ export default async function cli() {
if (cliFlags.rage) {
const {ragePath} = cliFlags;
const filename = clientFlags.cwd.resolve(
- ragePath === undefined
- ? `rome-rage-${getFilenameTimestamp()}.tar.gz`
- : ragePath,
+ ragePath === undefined ? `Rage-${getFilenameTimestamp()}.tgz` : ragePath,
).join();
await client.rage(filename, profileOptions);
return;

MODIFY
packages/@romejs/consume/Consumer.ts
packages/@romejs/consume/Consumer.ts
@@ -768,7 +768,7 @@ export default class Consumer {
this.declareDefinition({
type: 'date',
default: def,
- required: true,
+ required: def === undefined,
});
return this._asDate(def);
}
@@ -800,7 +800,7 @@ export default class Consumer {
this.declareDefinition({
type: 'boolean',
default: def,
- required: true,
+ required: def === undefined,
});
return this._asBoolean(def);
}
@@ -816,24 +816,27 @@ export default class Consumer {
// STRINGS
asStringOrVoid(def?: string): undefined | string {
+ if (this.exists()) {
+ return this.asString(def);
+ } else {
+ this._declareOptionalString(def);
+ return undefined;
+ }
+ }
+
+ _declareOptionalString(def?: string) {
this.declareDefinition({
type: 'string',
default: def,
required: false,
});
-
- if (this.exists()) {
- return this._asString(def);
- } else {
- return undefined;
- }
}
asString(def?: string): string {
this.declareDefinition({
type: 'string',
default: def,
- required: true,
+ required: def === undefined,
});
return this._asString(def);
}
@@ -900,7 +903,7 @@ export default class Consumer {
this.declareDefinition({
type: 'bigint',
default: def,
- required: true,
+ required: def === undefined,
});
return this._asBigInt(def);
}
@@ -921,8 +924,8 @@ export default class Consumer {
}
// PATHS
- asURLFilePath(): URLFilePath {
- const path = this.asUnknownFilePath();
+ asURLFilePath(def?: string): URLFilePath {
+ const path = this.asUnknownFilePath(def);
if (path.isURL()) {
return path.assertURL();
} else {
@@ -931,22 +934,54 @@ export default class Consumer {
}
}
- asUnknownFilePath(): UnknownFilePath {
- return createUnknownFilePath(this.asString());
+ asURLFilePathOrVoid(def?: string): undefined | URLFilePath {
+ if (this.exists()) {
+ return this.asURLFilePath(def);
+ } else {
+ this._declareOptionalString(def);
+ return undefined;
+ }
+ }
+
+ asUnknownFilePath(def?: string): UnknownFilePath {
+ return createUnknownFilePath(this.asString(def));
+ }
+
+ asUnknownFilePathOrVoid(def?: string): undefined | UnknownFilePath {
+ if (this.exists()) {
+ return this.asUnknownFilePath(def);
+ } else {
+ this._declareOptionalString(def);
+ return undefined;
+ }
}
- asAbsoluteFilePath(): AbsoluteFilePath {
- const path = this.asUnknownFilePath();
+ asAbsoluteFilePath(def?: string, cwd?: AbsoluteFilePath): AbsoluteFilePath {
+ const path = this.asUnknownFilePath(def);
if (path.isAbsolute()) {
return path.assertAbsolute();
+ } else if (cwd !== undefined && path.isRelative()) {
+ return cwd.resolve(path);
} else {
this.unexpected(descriptions.CONSUME.EXPECTED_ABSOLUTE_PATH);
return createAbsoluteFilePath('/').append(path);
}
}
- asRelativeFilePath(): RelativeFilePath {
- const path = this.asUnknownFilePath();
+ asAbsoluteFilePathOrVoid(
+ def?: string,
+ cwd?: AbsoluteFilePath,
+ ): undefined | AbsoluteFilePath {
+ if (this.exists()) {
+ return this.asAbsoluteFilePath(def, cwd);
+ } else {
+ this._declareOptionalString(def);
+ return undefined;
+ }
+ }
+
+ asRelativeFilePath(def?: string): RelativeFilePath {
+ const path = this.asUnknownFilePath(def);
if (path.isRelative()) {
return path.assertRelative();
} else {
@@ -955,8 +990,17 @@ export default class Consumer {
}
}
- asExplicitRelativeFilePath(): RelativeFilePath {
- const path = this.asRelativeFilePath();
+ asRelativeFilePathOrVoid(def?: string): undefined | RelativeFilePath {
+ if (this.exists()) {
+ return this.asRelativeFilePath(def);
+ } else {
+ this._declareOptionalString(def);
+ return undefined;
+ }
+ }
+
+ asExplicitRelativeFilePath(def?: string): RelativeFilePath {
+ const path = this.asRelativeFilePath(def);
if (path.isExplicitRelative()) {
return path;
@@ -966,6 +1010,15 @@ export default class Consumer {
}
}
+ asExplicitRelativeFilePathOrVoid(def?: string): undefined | RelativeFilePath {
+ if (this.exists()) {
+ return this.asExplicitRelativeFilePath(def);
+ } else {
+ this._declareOptionalString(def);
+ return undefined;
+ }
+ }
+
// NUMBER
asNumberOrVoid(def?: number): undefined | number {
this.declareDefinition({
@@ -993,7 +1046,7 @@ export default class Consumer {
this.declareDefinition({
type: 'number',
default: def,
- required: true,
+ required: def === undefined,
});
return this._asNumberFromString(def);
}
@@ -1031,7 +1084,7 @@ export default class Consumer {
this.declareDefinition({
type: 'number',
default: def,
- required: true,
+ required: def === undefined,
});
return this._asNumber(def);
}
@@ -1073,7 +1126,6 @@ export default class Consumer {
this.declareDefinition({
type: 'number-range',
default: opts.default,
- required: true,
// @ts-ignore
min,
max,

MODIFY
packages/@romejs/core/common/types/client.ts
packages/@romejs/core/common/types/client.ts
@@ -20,6 +20,8 @@ export const DEFAULT_CLIENT_FLAGS: ClientFlags = {
};
export const DEFAULT_CLIENT_REQUEST_FLAGS: ClientRequestFlags = {
+ ...DEFAULT_PRINTER_FLAGS,
+ showAllDiagnostics: false,
collectMarkers: false,
timing: false,
benchmark: false,
@@ -29,7 +31,6 @@ export const DEFAULT_CLIENT_REQUEST_FLAGS: ClientRequestFlags = {
resolverPlatform: undefined,
resolverScale: undefined,
resolverMocks: false,
- ...DEFAULT_PRINTER_FLAGS,
};
export type ClientRequestFlags = DiagnosticsPrinterFlags & {

Add CLI global flag descriptions