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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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