fix(core): handle large property names when running --help

This commit is contained in:
Victor Savkin 2022-03-24 17:20:48 -04:00
parent 3a87887b06
commit 85721e42f0
No known key found for this signature in database
GPG Key ID: 39178FEB7698B817

View File

@ -2,8 +2,16 @@ import { Schema } from './params';
import * as chalk from 'chalk'; import * as chalk from 'chalk';
import { logger, stripIndent } from './logger'; import { logger, stripIndent } from './logger';
function formatOption(name: string, description: string) { function formatOption(
return ` --${`${name} `.substr(0, 22)}${description}`; name: string,
description: string,
maxPropertyNameLength: number
) {
const lengthOfKey = Math.max(maxPropertyNameLength + 4, 22);
return ` --${`${name} `.substr(
0,
lengthOfKey
)}${description}`;
} }
export function printHelp( export function printHelp(
@ -18,18 +26,33 @@ export function printHelp(
return p['$default'] && p['$default']['$source'] === 'argv'; return p['$default'] && p['$default']['$source'] === 'argv';
}); });
const positional = allPositional.length > 0 ? ` [${allPositional[0]}]` : ''; const positional = allPositional.length > 0 ? ` [${allPositional[0]}]` : '';
const maxPropertyNameLength = Object.keys(schema.properties)
.map((n) => n.length)
.reduce((a, b) => Math.max(a, b), 0);
const args = Object.keys(schema.properties) const args = Object.keys(schema.properties)
.map((name) => { .map((name) => {
const d = schema.properties[name]; const d = schema.properties[name];
const def = d.default ? ` (default: ${d.default})` : ''; const def = d.default ? ` (default: ${d.default})` : '';
return formatOption(name, `${d.description}${def}`); return formatOption(
name,
`${d.description}${def}`,
maxPropertyNameLength
);
}) })
.join('\n'); .join('\n');
const missingFlags = const missingFlags =
meta.mode === 'generate' meta.mode === 'generate'
? formatOption('dry-run', 'Preview the changes without updating files') ? formatOption(
: formatOption('skip-nx-cache', 'Skip the use of Nx cache.'); 'dry-run',
'Preview the changes without updating files',
maxPropertyNameLength
)
: formatOption(
'skip-nx-cache',
'Skip the use of Nx cache.',
maxPropertyNameLength
);
let linkDescription = null; let linkDescription = null;
// we need to generalize link generation so it works for non-party-class plugins as well // we need to generalize link generation so it works for non-party-class plugins as well