-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: enhance cli version cmd (#76)
* ✨ Feat: introduce new version --verbose flag This commit introduces a `--verbose`/`-v` flag for the version command and the top-level logic for the version command to handle verbosity requests. * ✨ Feat: add version verbose logic This commit adds `version_manuscript.go` as a new file to the repo. Within, new structs are defined for handling version information for manuscript-core, docker, docker desktop,as well as the build time environment of rust, and go. Additionally, versioning information is pretty-printed to the console & emojified! * 🔖 [chore] bump version number to 1.1.0 The CLI was still displaying the old version number (1.0.4) ; this commit bumps the version var in the commander.go package so that the version command will display the proper version. * 💡 [chore] update build information about ldflags There was an error previously. Wording did not contain the correct path for the `go build`instructions in the source code comments of `version_manuscript.go`
- Loading branch information
1 parent
89faf24
commit 5b8690e
Showing
2 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |