github.com/twelho/conform@v0.0.0-20231016230407-c25e9238598a/cmd/conform/version.go (about) 1 // This Source Code Form is subject to the terms of the Mozilla Public 2 // License, v. 2.0. If a copy of the MPL was not distributed with this 3 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 package main 6 7 import ( 8 "github.com/spf13/cobra" 9 10 "github.com/twelho/conform/internal/version" 11 ) 12 13 var shortVersion bool 14 15 // versionCmd represents the version command. 16 var versionCmd = &cobra.Command{ 17 Use: "version", 18 Short: "Prints the version", 19 Long: ``, 20 Run: func(cmd *cobra.Command, args []string) { 21 if shortVersion { 22 version.PrintShortVersion() 23 } else { 24 version.PrintLongVersion() 25 } 26 }, 27 } 28 29 func init() { 30 versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print the short version") 31 rootCmd.AddCommand(versionCmd) 32 }