nezuhub's picture
download
raw
3.19 kB
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCommandHelp = exports.makeCommandHelpOption = void 0;
const chalk_1 = require("./chalk");
const makeCommandHelpOption = ({ option, description, value, }) => {
const valueSuffix = value === null
? ''
: ` ${value !== null && value !== void 0 ? value : (typeof option.type === 'boolean' ? '' : '<value>')}`;
return {
flag: `--${option.cliFlag}${valueSuffix}`.trimEnd(),
description: description !== null && description !== void 0 ? description : option.name,
};
};
exports.makeCommandHelpOption = makeCommandHelpOption;
const commandMatches = (command, selectedPath) => command.path.every((part, index) => selectedPath[index] === part) &&
selectedPath.length >= command.path.length;
const formatOption = (option, width) => {
return ` ${chalk_1.chalk.blue(option.flag.padEnd(width))}${option.description}`;
};
const getCommandHelp = ({ binaryName, commands, selectedPath, rootDocumentation, }) => {
const selectedCommand = commands
.filter((command) => commandMatches(command, selectedPath))
.sort((a, b) => b.path.length - a.path.length)[0];
if (selectedCommand) {
const displayPath = selectedPath
.slice(0, selectedCommand.path.length)
.join(' ');
const selectedBinaryName = displayPath
? `${binaryName} ${displayPath}`
: binaryName;
const children = commands.filter((command) => command.listed !== false &&
command.path.length === selectedCommand.path.length + 1 &&
selectedCommand.path.every((part, index) => command.path[index] === part));
const options = [
...selectedCommand.options,
{ flag: '--help', description: 'Show this help.' },
];
const optionWidth = Math.max(...options.map((option) => option.flag.length)) + 2;
const commandLines = [
'',
chalk_1.chalk.blue(selectedBinaryName) + chalk_1.chalk.gray(selectedCommand.args),
selectedCommand.description,
];
if (children.length > 0) {
commandLines.push('', 'Commands:');
for (const child of children) {
commandLines.push('', chalk_1.chalk.blue(`${binaryName} ${child.path.join(' ')}`) +
chalk_1.chalk.gray(child.args), child.description);
}
}
commandLines.push('', 'Options:', ...options.map((option) => formatOption(option, optionWidth)), '', chalk_1.chalk.gray(`Full documentation: ${selectedCommand.documentation}`));
return commandLines;
}
const lines = ['', 'Available commands:'];
for (const command of commands) {
if (command.path.length !== 1 || command.listed === false) {
continue;
}
lines.push('', chalk_1.chalk.blue(`${binaryName} ${command.path[0]}`) + chalk_1.chalk.gray(command.args), command.description, chalk_1.chalk.gray(command.documentation));
}
lines.push('', `Visit ${rootDocumentation} for browsable CLI documentation.`);
return lines;
};
exports.getCommandHelp = getCommandHelp;

Xet Storage Details

Size:
3.19 kB
·
Xet hash:
bd54d6c7d3fd9d2b4e0ba901d06f8682eac1e83bd565fad90a14a541b149e61e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.