-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add command alias support #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add command aliases using a hybrid API that supports both simple string
descriptions (backward compatible) and a CommandOptions object with
aliases array.
Features:
- Aliases work for both leaf commands and nested command groups
- Help output displays aliases in dimmer styling alongside command names
- Alias conflicts are detected at registration time
- New 'commandAlias' theme color for customizable alias styling
API:
// Simple (unchanged)
.command('add', parser, handler, 'Add an item')
// With aliases
.command('add', parser, handler, {
description: 'Add an item',
aliases: ['a', 'new']
})
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds command alias support to the bargs CLI framework, allowing commands to be invoked using alternative names (e.g., ls as an alias for list). The implementation uses a hybrid API that maintains backward compatibility with existing string descriptions while supporting a new CommandOptions object that includes an aliases array.
Key changes:
- Command aliases are registered and resolved for both leaf commands and nested command groups
- Help output displays aliases alongside command names with dimmer styling
- Alias conflicts are detected and reported at registration time
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.ts | Adds CommandOptions interface to support aliases and updates command registration signatures |
| src/bargs.ts | Implements alias registration, resolution logic, and conflict detection |
| src/help.ts | Updates help generation to display command aliases with appropriate styling |
| src/theme.ts | Adds commandAlias theme color for styling aliases differently from command names |
| src/index.ts | Exports CommandOptions type for public API |
| test/bargs.test.ts | Adds comprehensive test coverage for alias functionality including resolution and error cases |
| examples/tasks.ts | Demonstrates alias usage in a practical task management example |
| examples/nested-commands.ts | Demonstrates aliases in nested command groups |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Changed error message from 'is already registered for command' to 'conflicts with existing command name' for clarity when an alias conflicts with an existing command name. Co-Authored-By: Claude <noreply@anthropic.com>
Fixed usage documentation in nested-commands.ts that had lines incorrectly merged together, making the examples unreadable. Used @example with fenced code block to prevent prettier from reflowing the command examples. Co-Authored-By: Claude <noreply@anthropic.com>

Add command aliases using a hybrid API that supports both simple string
descriptions (backward compatible) and a CommandOptions object with
aliases array.
Features:
API:
// Simple (unchanged)
.command('add', parser, handler, 'Add an item')
// With aliases
.command('add', parser, handler, {
description: 'Add an item',
aliases: ['a', 'new']
})
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com