@tokens-studio/sdk
Version:
The official SDK for Tokens Studio
43 lines (40 loc) • 1.38 kB
JavaScript
import {} from './args-spec.js';
import { argsSpec, commands } from './args-spec.js';
export function createHelpOverview(command) {
let helpStr = '';
const binPrefix = `$ tokensstudio`;
helpStr += `Usage:
${binPrefix} ${command ?? '[root]'}`;
if (!command) {
helpStr += `
Commands:
${commands.join('\n ')}
For more info, run any command with the \`--help\` flag:
${binPrefix} --help
${commands.map((cmd) => `${binPrefix} ${cmd} --help`).join('\n ')}`;
}
const appliedFlags = Object.entries(argsSpec).filter(([optionKey, optionVal]) => optionKey.startsWith('--') && optionVal.appliesTo.includes(command));
if (appliedFlags.length > 0) {
const flagData = appliedFlags.map(([key, value]) => {
return { key, value, length: key.length };
});
let longest = 0;
flagData.forEach(({ length }) => {
if (length && length > longest) {
longest = length;
}
});
helpStr += `
Options:
${flagData
.map(({ key, value, length }) => {
const desc = `[${value.type.name.toLowerCase()}] ${value.desc}`;
const gap = longest - length;
return `${key} ${' '.repeat(gap)}${desc}`;
})
.join('\n ')}
`;
}
return helpStr;
}
//# sourceMappingURL=create-help-overview.js.map