diff --git a/commands/commander.go b/commands/commander.go index f9f9ac0..9425ce6 100644 --- a/commands/commander.go +++ b/commands/commander.go @@ -9,7 +9,7 @@ import ( var ( env string - version = "1.0.4" + version = "1.1.0" ) func Execute(args []string) error { @@ -176,12 +176,14 @@ var versionCmd = &cobra.Command{ Long: `ā„¹ļø Manuscript CLI Version Information Shows: -šŸ”· CLI version -šŸ”· Build info (coming soon) -šŸ”· API versions (coming soon)`, +šŸ› ļø Manuscript Core version +šŸ—ļø Build info +šŸ’» System information +šŸ³ Docker environment details`, Example: `>> manuscript-cli version`, Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("manuscript-cli version %s\n", version) + verbosity, _ := cmd.Flags().GetBool("verbose") + showVersion(verbosity) }, } @@ -212,6 +214,9 @@ func init() { deployManuscript.Flags().StringVar(&env, "env", "", "Specify the environment to deploy (local or chainbase)") deployManuscript.MarkFlagRequired("env") + // Configure version command flags + versionCmd.Flags().BoolP("verbose", "v", false, "Display detailed version information") + // Disable the default completion command rootCmd.CompletionOptions.HiddenDefaultCmd = true } diff --git a/commands/version_manuscript.go b/commands/version_manuscript.go new file mode 100644 index 0000000..2f5560c --- /dev/null +++ b/commands/version_manuscript.go @@ -0,0 +1,106 @@ +package commands + +import ( + "fmt" + "os/exec" + "runtime" + "strings" +) + +// Build-time variables set via ldflags +// Build command would be: +// +// go build -ldflags "-X manuscript-core/commands.gitCommit=$(git rev-parse --short HEAD) \ +// -X manuscript-core/commands.buildDate=$(date -u '+%Y-%m-%d:%H:%M:%S') \ +// -X manuscript-core/commands.goVersion=$(go version | cut -d' ' -f3) \ +// -X manuscript-core/commands.rustVersion=$(rustc --version | cut -d' ' -f2)" \ +// -o manuscript-cli main.go +var ( + gitCommit = "unknown" // Set by build flags + buildDate = "unknown" // Set by build flags + goVersion = "unknown" // Set by build flags + rustVersion = "unknown" // Set by build flags +) + +type VersionInfo struct { + Version string `json:"version"` + GoVersion string `json:"go_version"` + RustVersion string `json:"rust_version"` + GitCommit string `json:"git_commit"` + BuildDate string `json:"build_date"` + OS string `json:"os"` + Arch string `json:"arch"` + DockerInfo DockerInfo `json:"docker_info"` +} + +type DockerInfo struct { + Version string `json:"version"` + DesktopVersion string `json:"desktop_version"` +} + +func showVersion(verbose bool) { + info := getVersionInfo() + + if !verbose { + fmt.Printf("manuscript-core version %s\n", info.Version) + return + } + + fmt.Printf("\nšŸ“œ Manuscript Core:\n") + fmt.Printf(" Version:\t%s\n", info.Version) + + fmt.Printf("\nšŸ—ļø Build Information:\n") + fmt.Printf(" Go Version:\t%s\n", info.GoVersion) + fmt.Printf(" Rust Version:\t%s\n", info.RustVersion) + fmt.Printf(" Git Commit:\t%s\n", info.GitCommit) + fmt.Printf(" Built:\t%s\n", info.BuildDate) + + fmt.Printf("\nšŸ’» System Information:\n") + uname, _ := exec.Command("uname", "-a").Output() + fmt.Printf(" Unix Name:\t%s", string(uname)) + fmt.Printf(" OS/Arch:\t%s/%s\n", info.OS, info.Arch) + + fmt.Printf("\nšŸ³ Docker Environment:\n") + if info.DockerInfo.Version != "" { + fmt.Printf(" Docker:\t'%s'\n", info.DockerInfo.Version) + } + if info.DockerInfo.DesktopVersion != "" { + fmt.Printf(" Docker Desktop:\t'%s'\n", info.DockerInfo.DesktopVersion) + } +} + +func getVersionInfo() VersionInfo { + info := VersionInfo{ + Version: version, + GoVersion: goVersion, + RustVersion: rustVersion, + GitCommit: gitCommit, + BuildDate: buildDate, + OS: runtime.GOOS, + Arch: runtime.GOARCH, + } + + // Get Docker version + if dockerVersion, err := exec.Command("docker", "--version").Output(); err == nil { + version := strings.TrimSpace(string(dockerVersion)) + parts := strings.Split(version, " ") + if len(parts) >= 3 { + info.DockerInfo.Version = strings.Trim(parts[2], ",") + } + } + + // Get Docker Desktop version + cmd := exec.Command("docker", "version", "--format", "{{.Server}} {{.Server.Platform.Name}}") + if desktopVersion, err := cmd.Output(); err == nil { + // Find "Docker Desktop" and extract version + output := string(desktopVersion) + if strings.Contains(output, "Docker Desktop") { + parts := strings.Split(output, "Docker Desktop") + if len(parts) > 1 { + info.DockerInfo.DesktopVersion = strings.Split(parts[1], " ")[1] + } + } + } + + return info +}