2023-02-18 22:42:15 -06:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2025-02-14 14:31:24 -06:00
|
|
|
const versionStr = "0.7.7"
|
2023-02-18 22:42:15 -06:00
|
|
|
|
|
|
|
var (
|
|
|
|
versionCmd = &cobra.Command{
|
2023-03-10 16:01:02 -06:00
|
|
|
Use: "version [flags]",
|
2023-07-01 21:46:54 -05:00
|
|
|
Short: "Prints the version and exits",
|
|
|
|
Long: "Prints the version and exits. No arguments just prints the version number only.",
|
2023-02-18 22:42:15 -06:00
|
|
|
Run: version,
|
|
|
|
}
|
2023-03-10 16:01:02 -06:00
|
|
|
numOnly bool
|
2023-05-12 00:42:14 -05:00
|
|
|
vPre bool
|
2023-02-18 22:42:15 -06:00
|
|
|
)
|
|
|
|
|
2023-07-01 21:46:54 -05:00
|
|
|
func init() {
|
2023-07-01 22:02:32 -05:00
|
|
|
versionCmd.PersistentFlags().BoolVarP(&numOnly, "num", "n", false, "Output the version number only.")
|
2023-07-01 21:46:54 -05:00
|
|
|
versionCmd.PersistentFlags().BoolVarP(&vPre, "vpre", "V", false, "Output the version with v prefixed.")
|
|
|
|
}
|
2023-02-18 22:42:15 -06:00
|
|
|
|
2023-07-01 21:46:54 -05:00
|
|
|
func version(cmd *cobra.Command, args []string) {
|
2023-05-12 00:42:14 -05:00
|
|
|
|
|
|
|
if numOnly && !vPre {
|
2023-03-10 16:01:02 -06:00
|
|
|
fmt.Printf("%s\n", versionStr)
|
2023-07-01 21:46:54 -05:00
|
|
|
} else if vPre && !numOnly {
|
|
|
|
fmt.Printf("v%s\n", versionStr)
|
2023-03-10 16:01:02 -06:00
|
|
|
} else {
|
2023-07-01 21:46:54 -05:00
|
|
|
fmt.Printf("Backy version: %s\n", versionStr)
|
2023-03-10 16:01:02 -06:00
|
|
|
}
|
2023-02-18 22:42:15 -06:00
|
|
|
|
|
|
|
os.Exit(0)
|
|
|
|
}
|