-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
⚠Provide version information as a CLI option #1773
Conversation
@camilamacedo86 This PR goes in the same direction as #1691, moving another command out of the extra commands. I think that the API for frameworks with the new options is clearer, they only have to provide a string now instead of a full COBRA command, and it also has the added benefot of including |
A note in coverage: this PR moves part of the remaining code from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with. 👍 I have just a nit. See; https://github.com/kubernetes-sigs/kubebuilder/pull/1773/files#r518800235
Otherwise:
/approve
@estroz do you see any reason for we do not move forward here? WDYT?
pkg/cli/cli.go
Outdated
@@ -424,7 +442,7 @@ After the scaffold is written, api will run make on the project. | |||
make run | |||
`, | |||
c.commandName, c.commandName), | |||
|
|||
Version: c.version, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs, this is only necessary if the command doesn't define a version
command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs this has to do with -v
and --version
flags, not with version
command:
// Version defines the version for this command. If this value is non-empty and the command does not
// define a "version" flag, a "version" boolean flag will be added to the command and, if specified,
// will print content of the "Version" variable. A shorthand "v" flag will also be added if the
// command does not define one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I read that wrong. I don't think we want to expose a --version
and a version
command though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any damage done by being able to do kubebuilder version
, kubebuilder --version
and kubebuilder -v
. I think it actually improves UX as it doesn't have to know if it is a command or a flag. kubebuilder help
and kubebuilder --help
have the same behavior, right?
@estroz can we merge this? The only remaining comment is that you wouldn't add |
@Adirio the only hesitation I have is that most k8s tools like |
@estroz Removed the P.S.: if we set a |
Signed-off-by: Adrian Orive <[email protected]>
/retest |
# TODO: what does this thing do. | ||
opts=-ldflags "-X sigs.k8s.io/kubebuilder/v2/cmd/version.kubeBuilderVersion=$INJECT_KB_VERSION" | ||
# Injects the version into the cmd/version.go file | ||
opts=-ldflags "-X sigs.k8s.io/kubebuilder/v2/cmd.kubeBuilderVersion=$INJECT_KB_VERSION" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt about adding adding something like this to make build
, ex.
BUILD_VERSION=$(shell git descripe --dirty --tags --always)
BUILD_COMMIT=$(shell git rev-parse HEAD)
LD_FLAGS=-ldflags "-X sigs.k8s.io/kubebuilder/v2/cmd.kubeBuilderVersion=$(BUILD_VERSION) -X sigs.k8s.io/kubebuilder/v2/cmd.gitCommit=$(BUILD_COMMIT)"
build: ## Build the project locally
go build $(LD_FLAGS) -o bin/kubebuilder ./cmd
perhaps in a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Adirio, camilamacedo86, estroz The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Description
Provide a
WithVersion
CLIOption
that allows to provide a version string instead of having to create aversion
command and provide it as an extra command. When a version is provided this way, the CLI will create a version command automatically that prints this version string.Changes
cli.New
:WithVersion
. Creating a command and providing it withWithExtraCommands
should still work with the previous behavior, so this is not a breaking change, but frameworks usingkubebuilder
should migrate to the new approach.Version
andNewCmd
from packagecmd/version
. This package is not part of the library itself, but as it is exported, it may be used by third parties.