...

Source file src/github.com/ory/x/cmdx/version.go

Documentation: github.com/ory/x/cmdx

     1  /*
     2   * Copyright © 2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * @author		Aeneas Rekkas <aeneas+oss@aeneas.io>
    17   * @Copyright 	2015-2018 Aeneas Rekkas <aeneas+oss@aeneas.io>
    18   * @license 	Apache-2.0
    19   *
    20   */
    21  
    22  package cmdx
    23  
    24  import (
    25  	"fmt"
    26  	"os"
    27  
    28  	"github.com/spf13/cobra"
    29  )
    30  
    31  // Version returns a *cobra.Command that handles the `version` command.
    32  func Version(gitTag, gitHash, buildTime *string) *cobra.Command {
    33  	return &cobra.Command{
    34  		Use:   "version",
    35  		Short: "Show the build version, build time, and git hash",
    36  		Run: func(cmd *cobra.Command, args []string) {
    37  			if len(*gitTag) == 0 {
    38  				fmt.Fprintln(os.Stderr, "Unable to determine version because the build process did not properly configure it.")
    39  			} else {
    40  				fmt.Printf("Version:			%s\n", *gitTag)
    41  			}
    42  
    43  			if len(*gitHash) == 0 {
    44  				fmt.Fprintln(os.Stderr, "Unable to determine build commit because the build process did not properly configure it.")
    45  			} else {
    46  				fmt.Printf("Build Commit:	%s\n", *gitHash)
    47  			}
    48  
    49  			if len(*buildTime) == 0 {
    50  				fmt.Fprintln(os.Stderr, "Unable to determine build timestamp because the build process did not properly configure it.")
    51  			} else {
    52  				fmt.Printf("Build Timestamp:	%s\n", *buildTime)
    53  			}
    54  		},
    55  	}
    56  }
    57  

View as plain text