Skip to content

feat: add version command to scharf & add agents.edn spec#48

Merged
narenaryan merged 3 commits into
mainfrom
feat/add-version-command
May 20, 2026
Merged

feat: add version command to scharf & add agents.edn spec#48
narenaryan merged 3 commits into
mainfrom
feat/add-version-command

Conversation

@narenaryan

Copy link
Copy Markdown
Contributor

Description

This PR adds a new version command by embedding version.json file at run time.

This PR also introduces a new agents.edn file to be used by agents while developing on project

@narenaryan narenaryan self-assigned this May 20, 2026
@narenaryan narenaryan added the enhancement New feature or request 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; all changes are additive and the refactored command tree is covered by new tests.

The version embedding, newRootCmd refactor, and upgrade error-handling improvements are all straightforward and well-tested. The only notable finding is a small dead-code block in the upgrade command that poses no runtime risk.

main.go — the unreachable splitActionRef error branch after validateUpgradeInput.

Important Files Changed

Filename Overview
main.go Refactors main() into newRootCmd() for testability, embeds version.json, adds version command, and converts upgrade to RunE. Contains dead code: the splitActionRef error branch after validateUpgradeInput can never be reached.
main_test.go New test file with executeRoot helper and tests for version output and upgrade validation errors; straightforward and correct.
.goreleaser.yaml Adds a before hook that writes version.json with goreleaser template variables before the build; the sh -c printf approach is correct for POSIX platforms.
version.json Newly tracked file providing dev-build defaults for the embedded version info; consistent with go:embed requirement.
.gitignore Adds version.json and agent tooling paths to .gitignore; the version.json entry is ineffective for the already-tracked file without also running git rm --cached.
agents.edn New EDN spec file for AI agent tooling, documenting commands, conventions, modules, and permissions for the project.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[scharf CLI] --> B{command}
    B --> V1["--version flag\n(Cobra built-in)"]
    B --> V2["version subcommand"]
    B --> U["upgrade subcommand\n(now RunE)"]
    B --> OTHER["other commands\naudit/autofix/find/list/lookup/upgrade-all-sha"]

    V1 --> E1["rootCmd.Version\n= cliVersion()"]
    V2 --> E2["fmt.Fprintln(cmd.OutOrStdout(), cliVersion())"]
    E1 --> JSON["go:embed version.json"]
    E2 --> JSON

    JSON -->|"goreleaser build"| GR["goreleaser before hook\nwrites version/commit/date"]
    JSON -->|"go build / dev"| DEV["dev defaults\nversion: dev, commit: unknown"]

    U --> VAL["validateUpgradeInput()"]
    VAL -->|"error"| ERR["Usage to stderr\nSilenceUsage=true\nreturn error"]
    VAL -->|"ok"| RESOLVE["resolver.ResolveNext()"]
    RESOLVE -->|"error"| RETERR["return error"]
    RESOLVE -->|"ok"| OUT["print upgradedPin"]
Loading

Reviews (2): Last reviewed commit: "fix: silence the output" | Re-trigger Greptile

Comment thread main.go
Comment thread .gitignore
narenaryan and others added 2 commits May 19, 2026 20:20
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Signed-off-by: N3N9 <narenarya@live.com>
@narenaryan narenaryan merged commit a977a96 into main May 20, 2026
2 checks passed
@narenaryan narenaryan deleted the feat/add-version-command branch May 20, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant