-
Notifications
You must be signed in to change notification settings - Fork 654
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
base: main
Are you sure you want to change the base?
Conversation
…le.Cli package - basic implementation Co-authored-by: arturcic <[email protected]>
…atibility - all tests passing Co-authored-by: arturcic <[email protected]>
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 <[email protected]>
I've implemented a full replacement of ArgumentParser with Spectre.Console.Cli using POSIX compliant syntax. The new implementation:
All existing functionality is preserved while providing modern, standards-compliant CLI syntax. Commit 242709c addresses your feedback. |
… based on documentation Co-authored-by: arturcic <[email protected]>
I've enhanced the SpectreArgumentParser implementation using the CLI arguments documentation as input. The improvements include:
Commit 42b74b1 addresses your feedback. |
legacy syntax support is not needed, please drop it, keep only the POSIX syntax |
[Description("Format string for version output")] | ||
public string? Format { get; set; } | ||
|
||
[CommandOption("-v|--show-variable")] |
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 <[email protected]>
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
@@ -37,6 +37,7 @@ | |||
<PackageVersion Include="NUnit.Analyzers" Version="4.9.2" /> | |||
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" /> | |||
<PackageVersion Include="Shouldly" Version="4.3.0" /> | |||
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" /> |
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.
/// Argument parser that uses Spectre.Console.Cli for enhanced command line processing | ||
/// with POSIX compliant syntax | ||
/// </summary> | ||
internal class SpectreArgumentParser : IArgumentParser |
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 <[email protected]>
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 addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…eparate files Co-authored-by: arturcic <[email protected]>
@copilot check and fix the build |
…ngs, and fix null reference issues Co-authored-by: arturcic <[email protected]>
Summary
This PR replaces the custom
ArgumentParser
implementation withSpectreArgumentParser
that uses the Spectre.Console.Cli package for enhanced command line processing capabilities, while maintaining 100% backward compatibility.Changes Made
Spectre.Console.Cli
inDirectory.Packages.props
andGitVersion.App.csproj
IArgumentParser
interface using composition patternGitVersionAppModule
to useSpectreArgumentParser
instead ofArgumentParser
Implementation Approach
The implementation uses a conservative composition pattern where
SpectreArgumentParser
delegates actual argument parsing to the originalArgumentParser
to 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.