Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

CommandLineParser can now be instantiated directly without subclassing, useful for testing and simple CLI scenarios. The redundant _actions array field has been removed in favor of deriving the list from _actionsByName.values().

Changes

  • Removed abstract modifier from CommandLineParser class - no abstract methods exist, direct instantiation is safe
  • Eliminated _actions array field - redundant storage for action list
    • actions getter now returns Array.from(this._actionsByName.values())
    • Iterations use _actionsByName.values() directly
  • Updated JSDoc - changed "abstract base classes" to "base classes"
  • Added test verifying direct instantiation

Example

// Before: Required subclassing
class MyParser extends CommandLineParser {
  constructor() {
    super({ toolFilename: 'mytool', toolDescription: 'My tool' });
  }
}

// After: Direct instantiation now works
const parser = new CommandLineParser({
  toolFilename: 'mytool',
  toolDescription: 'My tool'
});
parser.addAction(myAction);

Backward compatible - existing subclasses continue to work unchanged.

Original prompt

On CommandLineParser.ts:57-57, Remove the abstract modifier from CommandLineParser. It is useful to be able to instantiate the class directly, e.g. in test classes, and no critical functionality (notably addAction) is restricted to subclasses.
Once it has been removed, generate a rush change file for ts-command-line as a patch.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 3, 2026 01:03
…_actions array

Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove abstract modifier from CommandLineParser class Remove abstract modifier from CommandLineParser and eliminate redundant _actions field Feb 3, 2026
Copilot AI requested a review from dmichon-msft February 3, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

2 participants