package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

// Build information set at compile time
var (
	version   = "1.0.0"
	gitCommit = "unknown"
	buildTime = "unknown"
)

// SetBuildInfo sets the build information from main package
func SetBuildInfo(v, commit, time string) {
	version = v
	gitCommit = commit
	buildTime = time
}

// GetBuildInfo returns the current build information
func GetBuildInfo() (string, string, string) {
	return version, gitCommit, buildTime
}

var versionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version number",
	Long:  `Print the version number of MapleFile backend.`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("MapleFile Backend v%s\n", version)
		fmt.Printf("Git Commit: %s\n", gitCommit)
		fmt.Printf("Build Time: %s\n", buildTime)
	},
}
