fix(cli): match command tree description separator

This commit is contained in:
Andrey Avtomonov 2026-05-13 00:27:39 +02:00
parent d4ce275a3c
commit e8a7018c55
3 changed files with 5 additions and 5 deletions

View file

@ -46,12 +46,12 @@ describe('walkCommandTree', () => {
describe('formatCommandTree', () => {
it('renders a single node with no children', () => {
const node = { name: 'solo', description: 'just me', aliases: [], children: [] };
expect(formatCommandTree(node)).toBe('solo - just me\n');
expect(formatCommandTree(node)).toBe('solo just me\n');
});
it('renders aliases in parentheses before the description', () => {
const node = { name: 'cmd', description: 'does things', aliases: ['c', 'co'], children: [] };
expect(formatCommandTree(node)).toBe('cmd (c, co) - does things\n');
expect(formatCommandTree(node)).toBe('cmd (c, co) does things\n');
});
it('omits the dash when description is empty', () => {
@ -75,7 +75,7 @@ describe('formatCommandTree', () => {
],
};
expect(formatCommandTree(tree)).toBe(
'root - top\n' + ' alpha (al) - a\n' + ' inner - i\n' + ' beta - b\n',
'root — top\n' + ' alpha (al) — a\n' + ' inner — i\n' + ' beta — b\n',
);
});
});

View file

@ -25,7 +25,7 @@ export function formatCommandTree(node: CommandTreeNode): string {
function appendNode(node: CommandTreeNode, depth: number, lines: string[]): void {
const indent = ' '.repeat(depth);
const aliasPart = node.aliases.length > 0 ? ` (${node.aliases.join(', ')})` : '';
const descriptionPart = node.description.length > 0 ? ` - ${node.description}` : '';
const descriptionPart = node.description.length > 0 ? ` ${node.description}` : '';
lines.push(`${indent}${node.name}${aliasPart}${descriptionPart}`);
const sortedChildren = [...node.children].sort((a, b) => a.name.localeCompare(b.name));

View file

@ -6,7 +6,7 @@ describe('renderKtxCommandTree', () => {
const output = renderKtxCommandTree();
const lines = output.split('\n');
expect(lines[0]).toMatch(/^ktx( |$|\s-)/);
expect(lines[0]).toMatch(/^ktx( |$|\s)/);
const topLevel = lines.filter((line) => /^ {2}\S/.test(line)).map((line) => line.trim().split(' ')[0]);