diff --git a/packages/cli/src/command-tree.test.ts b/packages/cli/src/command-tree.test.ts index 54dec54b..85fa0e84 100644 --- a/packages/cli/src/command-tree.test.ts +++ b/packages/cli/src/command-tree.test.ts @@ -88,7 +88,13 @@ describe('formatCommandTree', () => { aliases: [], arguments: [], children: [ - { name: 'beta', description: 'b', aliases: [], arguments: [], children: [] }, + { + name: 'beta', + description: 'b', + aliases: [], + arguments: [], + children: [{ name: 'leaf', description: 'l', aliases: [], arguments: [], children: [] }], + }, { name: 'alpha', description: 'a', @@ -101,7 +107,8 @@ describe('formatCommandTree', () => { const lines = formatCommandTree(tree).trimEnd().split('\n'); expect(lines[0]).toMatch(/^root\s+top$/); expect(lines[1]).toMatch(/^ ├── beta\s+b$/); - expect(lines[2]).toMatch(/^ └── alpha \(al\)\s+a$/); - expect(lines[3]).toMatch(/^ └── inner\s+i$/); + expect(lines[2]).toMatch(/^ │ └── leaf\s+l$/); + expect(lines[3]).toMatch(/^ └── alpha \(al\)\s+a$/); + expect(lines[4]).toMatch(/^ └── inner\s+i$/); }); }); diff --git a/packages/cli/src/command-tree.ts b/packages/cli/src/command-tree.ts index 65e3f5b2..2eeb24e8 100644 --- a/packages/cli/src/command-tree.ts +++ b/packages/cli/src/command-tree.ts @@ -35,10 +35,11 @@ function appendNode(node: CommandTreeNode, prefix: string, connector: string, li const label = formatLabel(node); lines.push(formatLine(`${prefix}${connector}${label}`, node.description)); + const childPrefix = + connector === '' ? `${prefix} ` : `${prefix}${connector === '└── ' ? ' ' : '│ '}`; node.children.forEach((child, index) => { const isLast = index === node.children.length - 1; const childConnector = isLast ? '└── ' : '├── '; - const childPrefix = connector === '' ? ' ' : `${prefix}${isLast ? ' ' : '│ '}`; appendNode(child, childPrefix, childConnector, lines); }); }