Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the GitVersion CLI by adopting POSIX-style --long-name arguments with short aliases (e.g., -l, -b). It introduces a new ArgumentParser backed by System.CommandLine and retains the existing logic as LegacyArgumentParser for backward compatibility. All internal usages, tests, build scripts, and documentation are updated to use the new argument style.
Changes:
- Introduces a new POSIX-style
ArgumentParserusingSystem.CommandLineand moves the old logic toLegacyArgumentParser. - Updates all internal invocations, build scripts, and tests to use the new
--long-nameargument style. - Updates documentation and
arguments.mdhelp text to reflect the new CLI argument conventions.
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/GitVersion.App/ArgumentParser.cs |
Core rewrite to use System.CommandLine for POSIX-style argument parsing |
src/GitVersion.App/LegacyArgumentParser.cs |
Old ArgumentParser logic preserved as LegacyArgumentParser |
src/GitVersion.App/GitVersionAppModule.cs |
DI registration updated to conditionally wire legacy or new parser |
src/GitVersion.App/HelpWriter.cs |
Method renamed to match legacy context |
src/GitVersion.App/GitVersion.App.csproj |
Adds System.CommandLine package reference |
src/Directory.Packages.props |
Adds System.CommandLine version entry |
src/GitVersion.App.Tests/ArgumentParserTests.cs |
Tests updated to new POSIX-style arguments |
src/GitVersion.App.Tests/LegacyArgumentParserTests.cs |
New test file covering legacy parser behavior |
src/GitVersion.App.Tests/HelpWriterTests.cs |
Updated to use legacy parser and new argument format |
src/GitVersion.App.Tests/ExecCmdLineArgumentTest.cs |
Integration tests updated to new argument style |
src/GitVersion.App.Tests/JsonOutputOnBuildServerTest.cs |
Integration tests updated to new argument style |
src/GitVersion.App.Tests/UpdateWixVersionFileTests.cs |
Integration tests updated to new argument style |
src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs |
Helper updated to new argument style |
src/GitVersion.App.Tests/Helpers/ProgramFixture.cs |
Fixture updated to new argument style |
src/GitVersion.App.Tests/VersionWriterTests.cs |
Updated to use legacy parser |
src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props |
Partially updated to new argument style |
build/common/Addins/GitVersion/GitVersionRunner.cs |
Build addin arguments updated |
build/common/Utilities/DockerContextExtensions.cs |
Docker test arguments updated |
build/build/Tasks/ValidateVersion.cs |
Validation task argument updated |
build/build/Tasks/Package/PackagePrepare.cs |
Package prepare argument updated |
tests/scripts/test-native-tool.sh |
Shell script updated to new argument style |
tests/scripts/test-global-tool.sh |
Shell script updated to new argument style |
docs/input/docs/usage/cli/arguments.md |
CLI argument documentation updated |
docs/input/docs/usage/cli/output.md |
Output documentation updated |
docs/input/docs/usage/cli/assembly-patch.md |
Assembly patch documentation updated |
docs/input/docs/reference/configuration.md |
Configuration docs updated |
docs/input/docs/reference/mdsource/configuration.source.md |
Source config docs updated |
docs/input/docs/reference/build-servers/*.md |
Build server docs updated |
docs/input/docs/learn/dynamic-repositories.md |
Dynamic repositories docs updated |
94d4c2a to
b7fa4c0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (5)
src/GitVersion.App/CliHost.cs:1
- The logic is inverted. The env var is named
USE_V6_ARGUMENT_PARSER, but the code maps it touseLegacyParser = true. "V6" refers to the new parser, while the legacy parser is the pre-v6 style. SettingUSE_V6_ARGUMENT_PARSER=trueshould select the new parser, but instead it selects the legacy parser. The variable name and the assignment are contradictory. Either rename the env var toUSE_LEGACY_ARGUMENT_PARSER, or invert the assignment touseLegacyParser = !string.Equals(envValue, "true", ...).
src/GitVersion.App/ArgumentParser.cs:1 - The
/?check here will never be satisfied because in the new POSIX-style parser,/?is not a registered argument and will be caught as an unrecognized token error earlier, or it would be treated as a path argument. More critically,/?is a legacy Windows-style help argument that the new parser should not need to handle. Keeping it here creates an inconsistency: the--prefix convention is being adopted, but/?is silently accepted as a help trigger in the new parser.
src/GitVersion.App/ArgumentParser.cs:1 - The short alias
-cis now assigned to--config, but according toBREAKING_CHANGES.md,-cpreviously referred to the commit id. The breaking changes document this reassignment and marks it as critical. However, the--commitoption defined on line 329 has no short alias, which matches the table, but this means any existing scripts using-c <commit-id>(which was documented in the old CLI and appears in several legacy parsers) will silently be interpreted as config file path instead of commit id. This is a silent semantic change that will be very difficult to diagnose. Consider at minimum a runtime warning when-cis used without a value that looks like a file path.
src/GitVersion.App/ArgumentParser.cs:1 - Blocking on
InvokeAsync()with.GetAwaiter().GetResult()in what may be a synchronous call context can lead to deadlocks, particularly in environments with a synchronization context (e.g., certain test runners or UI frameworks). Since this method is on a code path that simply needs to print help and return, consider using a synchronous invoke or ensuring the call chain is truly async-safe.
src/GitVersion.App/ArgumentParser.cs:1 - The
versionoption is defined and added to theRootCommand, but it is never read back viaparseResult.GetValue(options.Version)inMapParsedValues. The--versionhandling is done earlier via a manualAny()check before parsing, which means the option is effectively dead in the command schema. Having an unused declared option in the schema may confuseSystem.CommandLine's own--versionhandling (it has a built-in--versionoption concept), and could cause conflicts or unexpected behavior.
57b99f2 to
0075eeb
Compare
c9a2529 to
0cb892a
Compare
9752a3b to
7ca8fad
Compare
Renames the `SystemCommandLineArgumentParser` class and file to `ArgumentParser` for improved clarity. Applies minor code improvements like using the null-conditional operator and sealing the `CommandOptions` record.
Introduce lazy initialization for the System.CommandLine schema to improve performance on subsequent argument parsing calls. Refactors the ArgumentParser for enhanced efficiency.
Migrates GitVersion command-line arguments to use double-dash long options for improved clarity and consistency with modern CLI standards.
Introduce an environment variable to switch between argument parser implementations.
Include details on the POSIX-style CLI arguments
Adds tests to confirm -c maps to --config and --commit sets the commit ID, aligning with updated parser behavior.
Add a new `arguments.md` file detailing POSIX-style CLI arguments. Create separate run configurations to facilitate testing both existing and new argument parsing behaviors.
Ensures HelpWriterTests correctly asserts /switch argument syntax when configured for the legacy parser.
Improve clarity and detail of argument descriptions in the CLI parser. Configure help system to wrap text for better readability in large outputs.
643365a to
f3ae6db
Compare
f3ae6db to
4f0e272
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 49 out of 49 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (6)
src/GitVersion.App/CliHost.cs:1
- The environment variable name
USE_V6_ARGUMENT_PARSERis a magic string duplicated acrossCliHost.cs, the run configurations,BREAKING_CHANGES.md, and the migration guide. Consider extracting it to a named constant (e.g., in aCliConstantsclass) to make future renames easier and reduce the risk of typos.
src/GitVersion.App/GitVersionAppModule.cs:1 - When
useLegacyParserisfalse(the newArgumentParseris used),IHelpWriterandIVersionWriterare never registered. However,ArgumentParseritself no longer depends on them (they were removed from its constructor in this PR), so anything else in the DI container that may requireIHelpWriterorIVersionWriter(e.g., tests that resolveIHelpWriterdirectly viaConfigureServices) will fail to resolve.HelpWriterTestsandVersionWriterTestsalready passuseLegacyParser: true, but any future consumer using the default module without the legacy flag will be missing these registrations. Consider always registeringIHelpWriterandIVersionWriter, or at minimum registering them outside theif/elseblock.
src/GitVersion.App/ArgumentParser.cs:1 - The short alias
-cis now mapped to--config(config file path), whereas in v6 it was mapped to the commit ID. This is documented as a breaking change, but the alias collision means users who muscle-memory-c <commit>will silently set the config file path instead, which could produce confusing behavior rather than an error. Consider omitting the-cshort alias for--configso users are forced to use--configexplicitly and-c <commit>triggers an "unrecognized option" error instead of silently misrouting.
src/GitVersion.App/LegacyArgumentParser.cs:1 - This error message uses the old
-ensureassemblyinfo/updateprojectfilesswitch names rather than the legacy/ensureassemblyinfo//updateprojectfilesstyle that the legacy parser uses throughout. For consistency within the legacy parser, all switch references in error messages should use the/switchform (as seen elsewhere in this file, e.g., line 424).
src/GitVersion.App.Tests/LegacyArgumentParserTests.cs:1 - This assertion expects the message from
ParseUpdateAssemblyInfo(line 520 ofLegacyArgumentParser.cs), but the test case"-updateAssemblyInfo Assembly.cs Assembly1.cs -ensureassemblyinfo"actually triggersParseEnsureAssemblyInfolast (because-ensureassemblyinfois parsed after-updateAssemblyInfo).ParseEnsureAssemblyInfoat line 424 throws the same message with/ensureassemblyinfowording, so the test should still pass — however the path throughParseUpdateAssemblyInfoat line 520 uses-ensureassemblyinfo(different from the expected/ensureassemblyinfo). Verify which code path is actually exercised and ensure the expected message string exactly matches the thrown exception to avoid a false-passing test.
src/GitVersion.App/HelpWriter.cs:1 - C# raw string literal indentation stripping uses the column of the closing
"""as the baseline. The closing"""is indented by 23 spaces, so 23 spaces will be stripped from each interpolated line. Ifargscontains lines with less than 23 leading spaces (or lines that use different indentation), those lines will either be trimmed incorrectly or cause a compile error. Theversionvariable and any blank lines inargsshould be unaffected, but multi-line content inargsread from the markdown stream may not align to this indentation baseline. Consider using a simple string concatenation orstring.Formatto avoid the raw-literal indentation pitfall.
|



Description
Introduces a new command-line argument parser that adopts POSIX-style
--long-namearguments and short aliases. This change updates all internal GitVersion usages and documentation, while retaining the legacy parser for backward compatibility.Related Issue
Fixes #4844
Motivation and Context
Modernize the command-line interface for GitVersion, providing a more consistent and standardized argument parsing experience using POSIX conventions. This improves usability and alignment with current CLI best practices.
How Has This Been Tested?
Integration tests were updated, and new dedicated tests for both the POSIX-style and the legacy argument parsers were added to confirm functionality and backward compatibility.
Screenshots (if appropriate):
Checklist: