backy/cmd/version.go

40 lines
814 B
Go
Raw Normal View History

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
2024-11-19 20:25:00 +00:00
const versionStr = "0.5.0"
var (
versionCmd = &cobra.Command{
Use: "version [flags]",
Short: "Prints the version and exits",
Long: "Prints the version and exits. No arguments just prints the version number only.",
Run: version,
}
numOnly bool
2023-05-12 05:42:14 +00:00
vPre bool
)
func init() {
2023-07-02 03:02:32 +00:00
versionCmd.PersistentFlags().BoolVarP(&numOnly, "num", "n", false, "Output the version number only.")
versionCmd.PersistentFlags().BoolVarP(&vPre, "vpre", "V", false, "Output the version with v prefixed.")
}
func version(cmd *cobra.Command, args []string) {
2023-05-12 05:42:14 +00:00
if numOnly && !vPre {
fmt.Printf("%s\n", versionStr)
} else if vPre && !numOnly {
fmt.Printf("v%s\n", versionStr)
} else {
fmt.Printf("Backy version: %s\n", versionStr)
}
os.Exit(0)
}