-
Notifications
You must be signed in to change notification settings - Fork 26
/
version.go
46 lines (37 loc) · 990 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cli
import (
"fmt"
"log"
"github.com/bitrise-io/envman/output"
"github.com/bitrise-io/envman/version"
"github.com/urfave/cli"
)
// VersionOutputModel ...
type VersionOutputModel struct {
Version string `json:"version"`
BuildNumber string `json:"build_number"`
Commit string `json:"commit"`
}
func printVersionCmd(c *cli.Context) error {
fullVersion := c.Bool("full")
if err := output.ConfigureOutputFormat(c); err != nil {
log.Fatalf("Error: %s", err)
}
versionOutput := VersionOutputModel{
Version: version.Version,
}
if fullVersion {
versionOutput.BuildNumber = version.BuildNumber
versionOutput.Commit = version.Commit
}
if output.Format == output.FormatRaw {
if fullVersion {
fmt.Printf("version: %v\nbuild_number: %v\ncommit: %v\n", versionOutput.Version, versionOutput.BuildNumber, versionOutput.Commit)
} else {
fmt.Println(versionOutput.Version)
}
} else {
output.Print(versionOutput, output.Format)
}
return nil
}