Skip to content

Commit

Permalink
fix: remove alias help message
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Mar 3, 2023
1 parent 9096ed9 commit 68e2a2f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/breadc/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,14 @@ export function makeHelpCommand(
}
}

return commands;
const alias = new Map<string, Command>();
for (const cmd of commands) {
if (!alias.has(cmd.format)) {
alias.set(cmd.format, cmd);
}
}

return [...alias.values()];
}

const command: Command = {
Expand Down
36 changes: 36 additions & 0 deletions packages/breadc/test/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ describe('Alias command', () => {
await cli.run(['echo', ' world']);
expect(text).toBe('hello world');
});

it('should generate help message', async () => {
const cli = breadc('cli');
cli
.command('[message]')
.alias('echo')
.action(() => {});

expect(await cli.run(['--help'])).toMatchInlineSnapshot(`
"cli/unknown
Usage: cli [OPTIONS] [message]
Commands:
cli [message]
Options:
-h, --help Print help
-v, --version Print version
"
`);

expect(await cli.run(['echo', '--help'])).toMatchInlineSnapshot(`
"cli/unknown
Usage: cli [OPTIONS] [message]
Commands:
cli [message]
Options:
-h, --help Print help
-v, --version Print version
"
`);
});
});

describe('Version Command', () => {
Expand Down

0 comments on commit 68e2a2f

Please sign in to comment.