fix(help): use explicit indentation instead of console.group
The help output was indented by unclosed console.group() calls, which Bun keeps applying to every subsequent line. Because groups were never closed with console.groupEnd(), indentation accumulated per nesting level and pushed deep entries (e.g. "jj portainer test") far to the right. Replace the group-based helpers with an explicit INDENT constant and a depth parameter in generateHelp(), so each level is indented deterministically and the layout is stable regardless of console state.
This commit is contained in:
+9
-12
@@ -4,13 +4,7 @@ import fs from "fs-extra";
|
||||
|
||||
const cliConfig: any = {};
|
||||
|
||||
const emphasizeText = (...args) => {
|
||||
console.log(chalk.bold(...args));
|
||||
};
|
||||
|
||||
const italicEmphasizeGreen = (...args) => {
|
||||
console.group(chalk.italic.green.bold(...args));
|
||||
};
|
||||
const INDENT = " ";
|
||||
|
||||
const formatCommandSection = (cmd, prefixCmd, maxLen = 25) => {
|
||||
const formattedCmd = prefixCmd ? `${prefixCmd} ${cmd}` : cmd;
|
||||
@@ -25,22 +19,24 @@ const formatHelpSection = (desc, prefixDesc) => {
|
||||
return formattedDesc;
|
||||
};
|
||||
|
||||
const generateHelp = ({ cmds, prefixCmd = "", prefixDesc = "" }) => {
|
||||
const generateHelp = ({ cmds, prefixCmd = "", prefixDesc = "", depth = 0 }) => {
|
||||
const indent = INDENT.repeat(depth);
|
||||
for (const cmd of cmds) {
|
||||
const commandLabel = cmd?.postCommand ? `${cmd?.key} ${cmd?.postCommand}` : cmd?.key;
|
||||
if (cmd?.mainTitle) {
|
||||
italicEmphasizeGreen(cmd?.mainTitle);
|
||||
console.log(indent + chalk.italic.green.bold(cmd.mainTitle));
|
||||
if (cmd?.keys?.length > 0) {
|
||||
generateHelp({
|
||||
cmds: cmd?.keys || [],
|
||||
prefixCmd: cmd?.key,
|
||||
prefixDesc: cmd?.desc,
|
||||
depth: depth + 1,
|
||||
});
|
||||
} else {
|
||||
emphasizeText(formatCommandSection(commandLabel, prefixCmd, cmd?.maxLength), formatHelpSection(cmd?.desc, prefixDesc));
|
||||
console.log(indent + INDENT + chalk.bold(formatCommandSection(commandLabel, prefixCmd, cmd?.maxLength), formatHelpSection(cmd?.desc, prefixDesc)));
|
||||
}
|
||||
} else {
|
||||
emphasizeText(formatCommandSection(commandLabel, prefixCmd, cmd?.maxLength), formatHelpSection(cmd?.desc, prefixDesc));
|
||||
console.log(indent + chalk.bold(formatCommandSection(commandLabel, prefixCmd, cmd?.maxLength), formatHelpSection(cmd?.desc, prefixDesc)));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -78,7 +74,7 @@ const cliHelp = async () => {
|
||||
return;
|
||||
}
|
||||
console.log(chalk.blue.italic.bold("Usage: jj <COMMAND>"));
|
||||
console.group(chalk.blue.italic.bold("Commands:"));
|
||||
console.log(chalk.blue.italic.bold("Commands:"));
|
||||
|
||||
cliConfig.commandsObject = getJJConfigByKeyChain(`commands`);
|
||||
cliConfig.commandList = Object.keys(cliConfig.commandsObject).map((cmdKey) => ({
|
||||
@@ -88,6 +84,7 @@ const cliHelp = async () => {
|
||||
|
||||
generateHelp({
|
||||
cmds: cliConfig.commandList,
|
||||
depth: 1,
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user