-
Notifications
You must be signed in to change notification settings - Fork 659
Replace ArgumentParser with Spectre.Console.Cli package #4610
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
...le.Cli package - basic implementation Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
...atibility - all tests passing Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
I would prefer a full replacement of ArgumentParser with the semantics of it, use the POSIX compliant syntax
you can use https://github.com/GitTools/GitVersion/blob/main/docs/input/docs/usage/cli/arguments.md as input as well
...mentation using POSIX compliant syntax Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
I would prefer a full replacement of ArgumentParser with the semantics of it, use the POSIX compliant syntax
I've implemented a full replacement of ArgumentParser with Spectre.Console.Cli using POSIX compliant syntax. The new implementation:
- Uses double dashes for long options (--config, --output, --format)
- Single dashes for short options (-c, -o, -f, -l)
- Completely removes delegation to the original ArgumentParser
- Provides native Spectre.Console.Cli command parsing with GitVersionCommand and GitVersionSettings
All existing functionality is preserved while providing modern, standards-compliant CLI syntax. Commit 242709c addresses your feedback.
... based on documentation Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
you can use https://github.com/GitTools/GitVersion/blob/main/docs/input/docs/usage/cli/arguments.md as input as well
I've enhanced the SpectreArgumentParser implementation using the CLI arguments documentation as input. The improvements include:
- Fixed option mapping conflicts (separate
-cfor commit and--configfor configuration file) - Added
--target-pathoption as documented alternative to positional path argument - Implemented comprehensive legacy syntax support for forward slash options (
/output,/config, etc.) - Enhanced fallback handling for complex option combinations
- Ensured all documented CLI arguments are properly mapped and supported
Commit 42b74b1 addresses your feedback.
legacy syntax support is not needed, please drop it, keep only the POSIX syntax
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.
use -v for verbosity instead
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.
Changed to use -v for verbosity instead of show variable to follow standard CLI conventions. Commit d04a748.
... and update tests to use POSIX syntax Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
legacy syntax support is not needed, please drop it, keep only the POSIX syntax
Legacy syntax support has been removed. The implementation now supports only POSIX compliant syntax with double dashes for long options (--config, --output) and single dashes for short options (-c, -o, -f). All forward slash options have been eliminated and tests updated accordingly. Commit 0c05d92.
src/Directory.Packages.props
Outdated
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.
use the latest version instead
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.
Updated to use the latest stable version 0.50.0. Commit 3a4b8e9.
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.
keep one class per file
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.
Split SpectreArgumentParser.cs into separate files - one class per file. Each class is now in its own file: SpectreArgumentParser.cs, ParseResultStorage.cs, ArgumentInterceptor.cs, GitVersionCommand.cs, and GitVersionSettings.cs. Commit 3a4b8e9.
...conventions Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com- Triggering command:
/usr/lib/apt/methods/https(dns block)
- Triggering command:
If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
...eparate files Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
@copilot check and fix the build
...ngs, and fix null reference issues Co-authored-by: arturcic <1760506+arturcic@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Summary
This PR replaces the custom
ArgumentParserimplementation withSpectreArgumentParserthat uses the Spectre.Console.Cli package for enhanced command line processing capabilities, while maintaining 100% backward compatibility.Changes Made
Spectre.Console.CliinDirectory.Packages.propsandGitVersion.App.csprojIArgumentParserinterface using composition patternGitVersionAppModuleto useSpectreArgumentParserinstead ofArgumentParserImplementation Approach
The implementation uses a conservative composition pattern where
SpectreArgumentParserdelegates actual argument parsing to the originalArgumentParserto ensure zero regression risk:This approach:
Testing
Future Enhancements
This implementation provides the foundation for future enhancements using Spectre.Console.Cli features such as:
The conservative approach ensures these enhancements can be added incrementally without risk to existing functionality.
💡 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.