forked from gobuffalo/buffalo
/
version.go
40 lines (33 loc) · 865 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
package cmd
import (
"encoding/json"
"os"
"github.com/gobuffalo/buffalo/runtime"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var jsonOutput bool
func init() {
decorate("version", versionCmd)
versionCmd.Flags().BoolVar(&jsonOutput, "json", false, "Print information in json format")
RootCmd.AddCommand(versionCmd)
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version information",
Run: func(c *cobra.Command, args []string) {
if jsonOutput {
build := runtime.BuildInfo{}
build.Version = runtime.Version
enc := json.NewEncoder(os.Stderr)
enc.SetIndent("", " ")
enc.Encode(build)
return
}
logrus.Infof("Buffalo version is: %s", runtime.Version)
},
// needed to override the root level pre-run func
PersistentPreRunE: func(c *cobra.Command, args []string) error {
return nil
},
}