Skip to content

Commit

Permalink
Feat: Add --version flag to output current version number #560 (#573)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
rajeshkio authored Aug 3, 2024
1 parent 6bd5fc5 commit cda3942
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions docs/cli/karpor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit cda3942

Please sign in to comment.