Skip to content

Commit ff0aaf9

Browse files
jkatzJonathan S. Katz
authored andcommitted
Add --client flag to pgo version to return only pgo client version
This skips making a call to the API server so the user can know the version of the pgo client that they are using. This mimics the kubectl functionality, i.e. `kubectl version --client`. Issue: #1600
1 parent 00127eb commit ff0aaf9

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

docs/content/pgo-client/reference/pgo_version.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pgo version [flags]
1818
### Options
1919

2020
```
21-
-h, --help help for version
21+
--client Only return the version of the pgo client. This does not make a call to the API server.
22+
-h, --help help for version
2223
```
2324

2425
### Options inherited from parent commands
@@ -38,4 +39,4 @@ pgo version [flags]
3839

3940
* [pgo](/pgo-client/reference/pgo/) - The pgo command line interface.
4041

41-
###### Auto generated by spf13/cobra on 31-Dec-2019
42+
###### Auto generated by spf13/cobra on 4-Jun-2020

pgo/cmd/version.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import (
2424
"os"
2525
)
2626

27+
// ClientVersionOnly indicates that only the client version should be returned, not make
28+
// a call to the server
29+
var ClientVersionOnly bool
30+
2731
var versionCmd = &cobra.Command{
2832
Use: "version",
2933
Short: "Print version information for the PostgreSQL Operator",
@@ -38,24 +42,31 @@ var versionCmd = &cobra.Command{
3842

3943
func init() {
4044
RootCmd.AddCommand(versionCmd)
45+
versionCmd.Flags().BoolVar(&ClientVersionOnly, "client", false, "Only return the version of the pgo client. This does not make a call to the API server.")
4146
}
4247

4348
func showVersion() {
4449

50+
// print the client version
51+
fmt.Println("pgo client version " + msgs.PGO_VERSION)
52+
53+
// if the user selects only to display the client version, return here
54+
if ClientVersionOnly {
55+
return
56+
}
57+
58+
// otherwise, get the server version
4559
response, err := api.ShowVersion(httpclient, &SessionCredentials)
4660

4761
if err != nil {
4862
fmt.Println("Error: " + err.Error())
4963
os.Exit(2)
5064
}
5165

52-
fmt.Println("pgo client version " + msgs.PGO_VERSION)
53-
54-
if response.Status.Code == msgs.Ok {
55-
fmt.Println("pgo-apiserver version " + response.Version)
56-
} else {
66+
if response.Status.Code != msgs.Ok {
5767
fmt.Println("Error: " + response.Status.Msg)
58-
os.Exit(2)
68+
os.Exit(1)
5969
}
6070

71+
fmt.Println("pgo-apiserver version " + response.Version)
6172
}

0 commit comments

Comments
 (0)