mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-22 11:51:01 +02:00
fix(cli): match command tree description separator
This commit is contained in:
parent
d4ce275a3c
commit
e8a7018c55
3 changed files with 5 additions and 5 deletions
|
|
@ -46,12 +46,12 @@ describe('walkCommandTree', () => {
|
||||||
describe('formatCommandTree', () => {
|
describe('formatCommandTree', () => {
|
||||||
it('renders a single node with no children', () => {
|
it('renders a single node with no children', () => {
|
||||||
const node = { name: 'solo', description: 'just me', aliases: [], 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', () => {
|
it('renders aliases in parentheses before the description', () => {
|
||||||
const node = { name: 'cmd', description: 'does things', aliases: ['c', 'co'], children: [] };
|
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', () => {
|
it('omits the dash when description is empty', () => {
|
||||||
|
|
@ -75,7 +75,7 @@ describe('formatCommandTree', () => {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
expect(formatCommandTree(tree)).toBe(
|
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',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export function formatCommandTree(node: CommandTreeNode): string {
|
||||||
function appendNode(node: CommandTreeNode, depth: number, lines: string[]): void {
|
function appendNode(node: CommandTreeNode, depth: number, lines: string[]): void {
|
||||||
const indent = ' '.repeat(depth);
|
const indent = ' '.repeat(depth);
|
||||||
const aliasPart = node.aliases.length > 0 ? ` (${node.aliases.join(', ')})` : '';
|
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}`);
|
lines.push(`${indent}${node.name}${aliasPart}${descriptionPart}`);
|
||||||
|
|
||||||
const sortedChildren = [...node.children].sort((a, b) => a.name.localeCompare(b.name));
|
const sortedChildren = [...node.children].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ describe('renderKtxCommandTree', () => {
|
||||||
const output = renderKtxCommandTree();
|
const output = renderKtxCommandTree();
|
||||||
|
|
||||||
const lines = output.split('\n');
|
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]);
|
const topLevel = lines.filter((line) => /^ {2}\S/.test(line)).map((line) => line.trim().split(' ')[0]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue