Refactor help and version command handling#4838
Conversation
Relocates the processing of --help and --version options to GitVersionApp, decoupling IVersionWriter and IHelpWriter dependencies from GitVersionExecutor.
Relocate help and version output logic from `GitVersionApp` to `ArgumentParser`. Simplify `GitVersionApp` startup by removing `IServiceProvider` dependency for these commands.
There was a problem hiding this comment.
Pull request overview
Centralizes handling of help and version commands by moving their output logic away from the main execution path and into argument parsing, aiming to simplify GitVersionApp/GitVersionExecutor flow.
Changes:
- Removed help/version handling from
GitVersionExecutorand refactored initialization logic. - Added help/version output side effects to
ArgumentParserduring parsing. - Short-circuited
GitVersionAppexecution whenIsHelporIsVersionis set.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/GitVersion.App/GitVersionExecutor.cs | Removes help/version dispatch; introduces Initialize() and always runs the main tool. |
| src/GitVersion.App/GitVersionApp.cs | Exits early for help/version commands before running the executor. |
| src/GitVersion.App/ArgumentParser.cs | Writes help/version output during argument parsing and sets corresponding flags. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
src/GitVersion.App/ArgumentParser.cs:61
- In this primary-constructor class, call
this.helpWriter.Write()rather thanhelpWriter.Write(). Referencing the primary constructor parameter from an instance method can cause it to be captured into a compiler-generated hidden field, duplicating state and adding a small amount of overhead; using the validatedprivate readonlyfield avoids that.
{
helpWriter.Write();
return new Arguments
src/GitVersion.App/ArgumentParser.cs:70
- Use
this.versionWriter.Write(assembly)instead ofversionWriter.Write(assembly)so the method uses the initialized field rather than capturing the primary constructor parameter into a hidden compiler field.
if (firstArgument.IsSwitch("version"))
{
var assembly = Assembly.GetExecutingAssembly();
versionWriter.Write(assembly);
Extracts configuration display to an early exit and ensures consistent application shutdown in a `finally` block, clarifying handling for special commands.
ca0121e to
5eea7e4
Compare
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/GitVersion.App/ArgumentParser.cs:74
ParseArgumentsnow produces side effects by writing help/version output viaIHelpWriter/IVersionWriter. ExistingArgumentParserTestscover-hand-versionparsing, but they don't verify the new behavior (that the corresponding writer is invoked and output is produced during parsing). Adding targeted tests (e.g., with a stub console or mocked writer) will prevent regressions whereIsHelp/IsVersionis set but no output is emitted.
if (firstArgument.IsHelp())
{
this.helpWriter.Write();
return new Arguments
{
IsHelp = true
};
}
if (firstArgument.IsSwitch("version"))
{
var assembly = Assembly.GetExecutingAssembly();
this.versionWriter.Write(assembly);
return new Arguments
{
IsVersion = true
};
|
Thank you @arturcic for your contribution! |



Move help and version output logic from
GitVersionApptoArgumentParser, centralizing command handling. This simplifies the application's main execution flow by delegating output responsibility.Fixes #4839