From cda3942d87a81b8550d2015af990bd83e897b233 Mon Sep 17 00:00:00 2001 From: Rajesh Kumar <107089376+rajeshkio@users.noreply.github.com> Date: Sat, 3 Aug 2024 12:11:16 +0530 Subject: [PATCH] Feat: Add --version flag to output current version number #560 (#573) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What type of PR is this? /kind feature ## What this PR does / why we need it: Add the -version flag to output the current version number. $ karpor --version v0.4.5 $ karpor -V v0.4.5 If I have Karpor's binary or image, I can’t directly know its current version unless it starts. ## Which issue(s) this PR fixes: Fixes #560 --- cmd/app/server.go | 7 +++++++ docs/cli/karpor.md | 1 + 2 files changed, 8 insertions(+) diff --git a/cmd/app/server.go b/cmd/app/server.go index c8f740fe..31237d4d 100644 --- a/cmd/app/server.go +++ b/cmd/app/server.go @@ -106,6 +106,10 @@ func NewServerCommand(ctx context.Context) *cobra.Command { Short: "Launch an API server", Long: "Launch an API server", RunE: func(c *cobra.Command, args []string) error { + if versionFlag, _ := c.Flags().GetBool("version"); versionFlag { + fmt.Println("Karpor version:", version.GetVersion()) + return nil + } if err := o.Complete(); err != nil { return err } @@ -119,6 +123,9 @@ func NewServerCommand(ctx context.Context) *cobra.Command { }, } + // Add version flag + cmd.Flags().BoolP("version", "V", false, "Print version and exit") + o.AddFlags(cmd.Flags()) return cmd } diff --git a/docs/cli/karpor.md b/docs/cli/karpor.md index edb8e6f3..3de868b5 100644 --- a/docs/cli/karpor.md +++ b/docs/cli/karpor.md @@ -220,6 +220,7 @@ karpor [flags] --tls-private-key-file string File containing the default x509 private key matching --tls-cert-file. (default "apiserver.local.config/certificates/apiserver.key") --tls-sni-cert-key namedCertKey A pair of x509 certificate and private key file paths, optionally suffixed with a list of domain patterns which are fully qualified domain names, possibly with prefixed wildcard segments. The domain patterns also allow IP addresses, but IPs should only be used if the apiserver has visibility to the IP address requested by a client. If no domain patterns are provided, the names of the certificate are extracted. Non-wildcard matches trump over wildcard matches, explicit domain patterns trump over extracted names. For multiple key/certificate pairs, use the --tls-sni-cert-key multiple times. Examples: "example.crt,example.key" or "foo.crt,foo.key:*.foo.com,foo.com". (default []) --tracing-config-file string File with apiserver tracing configuration. + -V --version Print version and exit. --watch-cache Enable watch caching in the apiserver (default true) --watch-cache-sizes strings Watch cache size settings for some resources (pods, nodes, etc.), comma separated. The individual setting format: resource[.group]#size, where resource is lowercase plural (no version), group is omitted for resources of apiVersion v1 (the legacy core API) and included for others, and size is a number. This option is only meaningful for resources built into the apiserver, not ones defined by CRDs or aggregated from external servers, and is only consulted if the watch-cache is enabled. The only meaningful size setting to supply here is zero, which means to disable watch caching for the associated resource; all non-zero values are equivalent and mean to not disable watch caching for that resource ```