Released v1
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show version information",
|
||||
Long: "Display the current version of pcli",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
version := getVersion()
|
||||
fmt.Println(version)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
|
||||
func getVersion() string {
|
||||
// Try to get version from git tag
|
||||
version, err := exec.Command("git", "describe", "--tags", "--exact-match").Output()
|
||||
if err == nil && len(version) > 0 {
|
||||
return string(version)
|
||||
}
|
||||
|
||||
// Fallback to timestamp-based version
|
||||
dateCmd := exec.Command("date", "+%Y%m%d-%H%M%S")
|
||||
date, err := dateCmd.Output()
|
||||
if err != nil {
|
||||
// Ultimate fallback
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
return "v" + string(date)
|
||||
}
|
||||
Reference in New Issue
Block a user