mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
fix(cli): preserve tree continuation guides
This commit is contained in:
parent
39f0320c2b
commit
5e057f97e3
2 changed files with 12 additions and 4 deletions
|
|
@ -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 <id> \(al\)\s+a$/);
|
||||
expect(lines[3]).toMatch(/^ └── inner\s+i$/);
|
||||
expect(lines[2]).toMatch(/^ │ └── leaf\s+l$/);
|
||||
expect(lines[3]).toMatch(/^ └── alpha <id> \(al\)\s+a$/);
|
||||
expect(lines[4]).toMatch(/^ └── inner\s+i$/);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue