Skip to content

Refactor help and version command handling#4838

Merged
arturcic merged 3 commits intoGitTools:mainfrom
arturcic:feature/refactor-help-version
Mar 2, 2026
Merged

Refactor help and version command handling#4838
arturcic merged 3 commits intoGitTools:mainfrom
arturcic:feature/refactor-help-version

Conversation

@arturcic
Copy link
Member

@arturcic arturcic commented Mar 2, 2026

Move help and version output logic from GitVersionApp to ArgumentParser, centralizing command handling. This simplifies the application's main execution flow by delegating output responsibility.

Fixes #4839

arturcic added 2 commits March 2, 2026 19:39
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.
Copilot AI review requested due to automatic review settings March 2, 2026 19:19
@arturcic arturcic added this to the 6.x milestone Mar 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GitVersionExecutor and refactored initialization logic.
  • Added help/version output side effects to ArgumentParser during parsing.
  • Short-circuited GitVersionApp execution when IsHelp or IsVersion is 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 than helpWriter.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 validated private readonly field avoids that.
        {
            helpWriter.Write();
            return new Arguments

src/GitVersion.App/ArgumentParser.cs:70

  • Use this.versionWriter.Write(assembly) instead of versionWriter.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.
@arturcic arturcic force-pushed the feature/refactor-help-version branch from ca0121e to 5eea7e4 Compare March 2, 2026 20:23
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • ParseArguments now produces side effects by writing help/version output via IHelpWriter/IVersionWriter. Existing ArgumentParserTests cover -h and -version parsing, 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 where IsHelp/IsVersion is 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
            };

@arturcic arturcic merged commit 0d25ac2 into GitTools:main Mar 2, 2026
122 checks passed
@arturcic arturcic deleted the feature/refactor-help-version branch March 2, 2026 20:49
@mergify
Copy link
Contributor

mergify bot commented Mar 2, 2026

Thank you @arturcic for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ISSUE]: Refactor help and version command handling

2 participants