Skip to content

fix: remove rootCmd.SetVersionTemplate(...) to reduce binary size#50

Merged
narenaryan merged 2 commits into
mainfrom
fix/binary-size-inflation
May 20, 2026
Merged

fix: remove rootCmd.SetVersionTemplate(...) to reduce binary size#50
narenaryan merged 2 commits into
mainfrom
fix/binary-size-inflation

Conversation

@narenaryan

@narenaryan narenaryan commented May 20, 2026

Copy link
Copy Markdown
Contributor

Description

v1.4.0 introduced a binary inflation problem (~1.5 MB bump per binary).

The fix is to remove rootCmd.SetVersionTemplate(...) Cobra template entirely and implement custom arg handling.

@narenaryan narenaryan self-assigned this May 20, 2026
@narenaryan narenaryan added the bug Something isn't working label May 20, 2026
@greptile-apps

greptile-apps Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is a targeted replacement of Cobra's version-template mechanism with an equivalent custom flag and handler.

Both the --version/-V flag path and the version subcommand call cliVersion() through the same fmt.Fprintln call, so the output is guaranteed identical. The test now validates all three entry points for both content and format. No existing behaviour is regressed; the only observable difference is the removal of the Cobra-generated version-flag line from --help output and the addition of -V as the short form.

No files require special attention.

Important Files Changed

Filename Overview
main.go Removes Cobra version template plumbing; adds a local BoolP flag + Run handler that mirrors the existing version subcommand. Logic is straightforward and correct.
main_test.go Adds -V coverage, a HasPrefix assertion for the new output format, and a cross-invocation consistency check. Test structure is sound.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([scharf invoked]) --> B{Has args?}
    B -- "--version or -V flag" --> C[rootCmd.Run]
    B -- "version subcommand" --> D[cmdVersion.Run]
    B -- "no relevant args" --> E[rootCmd.Run]
    B -- "other subcommand" --> F[respective subcommand Run]

    C --> G{showVersion == true?}
    G -- yes --> H[fmt.Fprintln cliVersion]
    G -- no --> I[cmd.Help]

    D --> J[fmt.Fprintln cliVersion]

    H --> K([stdout: version: X.Y.Z ...])
    J --> K
Loading

Reviews (2): Last reviewed commit: "feat: add -V option" | Re-trigger Greptile

Comment thread main_test.go Outdated
Comment thread main.go Outdated
@narenaryan narenaryan merged commit d51c21e into main May 20, 2026
2 checks passed
@narenaryan narenaryan deleted the fix/binary-size-inflation branch May 20, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant