Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added version argument on the CLI #19

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

krishnaduttPanchagnula
Copy link
Contributor

Closes #15

Copy link
Collaborator

@garethr garethr left a comment

Choose a reason for hiding this comment

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

First up, thanks for taking a run at this.

Unfortunately, the approach of shelling out to git won't work unless someone is running from source. If you're happy to take another run, the following should help. But happy to answer questions too in the comments.

Cobra supports a Version property rather than needing a new command. You can see that in use https://github.com/open-policy-agent/conftest/blob/master/internal/commands/default.go#LL32C24-L32C24

Typically that's calculated at build time, and then passed to the compilation step, like so https://github.com/open-policy-agent/conftest/blob/master/.goreleaser.yml#L17-L20

You can see some of the implementation here
https://github.com/open-policy-agent/conftest/blob/master/internal/commands/default.go#L22-L25

internal/commands/version/version.go Outdated Show resolved Hide resolved
internal/commands/version/version.go Outdated Show resolved Hide resolved
internal/commands/version/version.go Outdated Show resolved Hide resolved
@krishnaduttPanchagnula
Copy link
Contributor Author

@garethr but in https://github.com/snyk/parlay/blob/main/.goreleaser.yml#21-L24 the line is commented out.

@krishnaduttPanchagnula
Copy link
Contributor Author

@garethr Thanks for your guidance. I implemented change with cobra's version attribute. I have enabled command in the goreleaser to get the version. but i am not sure where does the goreleaser will get the version. i am currently researching that, it would be helpful if can share any insights you might have.

@garethr
Copy link
Collaborator

garethr commented Jun 24, 2023

Goreleaser is opionated about versions, and then exposes that as a template variable {{.Version}} in the config. You can see the docs for this here https://goreleaser.com/customization/templates/

That's what this example uses:
https://github.com/open-policy-agent/conftest/blob/master/.goreleaser.yml#L20

ldflags are a way of passing buildtime information to be embedded in the resulting binary https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications

The above example binds the value passed in to this variable
https://github.com/open-policy-agent/conftest/blob/master/internal/commands/default.go#L23-L25

Copy link
Contributor Author

@krishnaduttPanchagnula krishnaduttPanchagnula left a comment

Choose a reason for hiding this comment

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

resolved these issues. Can you review it once @garethr

Copy link
Collaborator

@garethr garethr left a comment

Choose a reason for hiding this comment

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

Quick scan of this, this looks great. One minor typo and good to merge this I think. Much appreciated.

internal/commands/default.go Outdated Show resolved Hide resolved
@mcombuechen mcombuechen dismissed garethr’s stale review March 1, 2024 06:56

Dismissing stale review (typo was fixed in meantime) to merge and release.

@krishnaduttPanchagnula krishnaduttPanchagnula requested a review from a team as a code owner March 1, 2024 07:06
@mcombuechen mcombuechen merged commit 3b2986a into snyk:main Mar 1, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a mechanism to get the version on the CLI
3 participants