blob: 7f7daf4ade783ee46b1a2f4e244c7106d9bcccb7 [file] [log] [blame]
Scott Baker2c0ebda2019-05-06 16:55:47 -07001/*
2 * Portions copyright 2019-present Open Networking Foundation
3 * Original copyright 2019-present Ciena Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package commands
18
19import (
20 flags "github.com/jessevdk/go-flags"
21 "github.com/opencord/cordctl/cli/version"
22 "github.com/opencord/cordctl/format"
23)
24
25type VersionDetails struct {
26 Version string `json:"version"`
27 GoVersion string `json:"goversion"`
28 GitCommit string `json:"gitcommit"`
29 BuildTime string `json:"buildtime"`
30 Os string `json:"os"`
31 Arch string `json:"arch"`
32}
33
34type VersionOutput struct {
35 Client VersionDetails `json:"client"`
36}
37
38type VersionOpts struct {
39 OutputAs string `short:"o" long:"outputas" default:"table" choice:"table" choice:"json" choice:"yaml" description:"Type of output to generate"`
40}
41
42var versionOpts = VersionOpts{}
43
44var versionInfo = VersionOutput{
45 Client: VersionDetails{
46 Version: version.Version,
47 GoVersion: version.GoVersion,
48 GitCommit: version.GitCommit,
49 Os: version.Os,
50 Arch: version.Arch,
51 BuildTime: version.BuildTime,
52 },
53}
54
55func RegisterVersionCommands(parent *flags.Parser) {
56 parent.AddCommand("version", "display version", "Display client version", &versionOpts)
57}
58
59const DefaultFormat = `Client:
60 Version {{.Client.Version}}
61 Go version: {{.Client.GoVersion}}
62 Git commit: {{.Client.GitCommit}}
63 Built: {{.Client.BuildTime}}
64 OS/Arch: {{.Client.Os}}/{{.Client.Arch}}
65`
66
67func (options *VersionOpts) Execute(args []string) error {
68 result := CommandResult{
69 Format: format.Format(DefaultFormat),
70 OutputAs: toOutputType(options.OutputAs),
71 Data: versionInfo,
72 }
73
74 GenerateOutput(&result)
75 return nil
76}