github.com/awslabs/clencli@v0.0.0-20210514234156-7ecf17182a20/cobra/controller/version.go (about) 1 /* 2 Copyright © 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package controller 17 18 import ( 19 "fmt" 20 "os" 21 "runtime" 22 23 "github.com/awslabs/clencli/box" 24 "github.com/awslabs/clencli/helper" 25 "github.com/sirupsen/logrus" 26 "github.com/spf13/cobra" 27 ) 28 29 // VersionCmd command to display clencli current version 30 func VersionCmd() *cobra.Command { 31 man, err := helper.GetManual("version") 32 if err != nil { 33 fmt.Println(err) 34 os.Exit(1) 35 } 36 37 return &cobra.Command{ 38 Use: man.Use, 39 Short: man.Short, 40 Long: man.Long, 41 RunE: versionRun, 42 } 43 } 44 45 func versionRun(cmd *cobra.Command, args []string) error { 46 // Get the version defined in the VERSION file 47 cmd.SilenceUsage = true 48 49 version, found := box.Get("/VERSION") 50 if !found { 51 logrus.Errorf("unable to find VERSION file under box/resources") 52 return fmt.Errorf("version not available") 53 } 54 55 goOS := runtime.GOOS 56 goVersion := runtime.Version() 57 goArch := runtime.GOARCH 58 59 cmd.Printf("clencli v%s %s %s %s\n", version, goVersion, goOS, goArch) 60 61 return nil 62 }