mirror of
https://github.com/Cheviiot/Vintner.git
synced 2026-08-03 15:57:24 +00:00
Uses Go's automatic VCS build-info stamping (vcs.revision/vcs.time/ vcs.modified, embedded by `go build` since Go 1.18 - no -ldflags changes needed, works the same for a CI release build and a plain local `go build`). Knowing the exact commit a bug report's binary was built from, not just the X.Y.Z tag, is the point - two builds of the same tag could still differ. Split the pure formatting logic (formatVersion) from the debug.ReadBuildInfo() call so it's actually unit-testable: `go test` binaries don't get VCS stamping the way `go build` ones do, so there was no way to exercise the revision-formatting branch through versionString() itself.
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
// Command vintner cross compiles with the real MSVC toolchain on Linux
|
|
// via Wine. It's a multi-call binary that behaves as `cl`, `link`, `lib`,
|
|
// `rc`, `midl`, `mt`, `dumpbin`, `msbuild`, etc. when invoked under one of
|
|
// those names (via symlinks set up by `vintner install`), and
|
|
// otherwise exposes the `download`/`install`/`env`/`version` management
|
|
// subcommands.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/Cheviiot/vintner/internal/i18n"
|
|
"github.com/Cheviiot/vintner/internal/wrapper"
|
|
)
|
|
|
|
// version is set at build time via -ldflags "-X main.version=X.Y.Z";
|
|
// left as "dev" for plain `go build`/`go run`.
|
|
var version = "dev"
|
|
|
|
func main() {
|
|
base := filepath.Base(os.Args[0])
|
|
name := strings.TrimSuffix(strings.ToLower(base), ".exe")
|
|
|
|
if _, ok := wrapper.Tools[name]; ok {
|
|
os.Exit(wrapper.Run(name, os.Args[1:]))
|
|
}
|
|
if name == "cmd" || name == "findstr" {
|
|
os.Exit(wrapper.Run(name, os.Args[1:]))
|
|
}
|
|
|
|
os.Exit(runCLI(os.Args[1:]))
|
|
}
|
|
|
|
func runCLI(args []string) int {
|
|
if len(args) == 0 {
|
|
printUsage()
|
|
return 1
|
|
}
|
|
|
|
switch args[0] {
|
|
case "download", "dl":
|
|
return runDownload(args[1:])
|
|
case "install", "i":
|
|
return runInstall(args[1:])
|
|
case "env", "e":
|
|
return runEnv(args[1:])
|
|
case "completion":
|
|
return runCompletion(args[1:])
|
|
case "version", "v", "--version":
|
|
fmt.Println(versionString())
|
|
return 0
|
|
case "-h", "--help", "help", "h":
|
|
printUsage()
|
|
return 0
|
|
default:
|
|
fmt.Fprint(os.Stderr, i18n.T("main.unknown_subcommand", args[0]))
|
|
printUsage()
|
|
return 1
|
|
}
|
|
}
|
|
|
|
func printUsage() {
|
|
fmt.Fprint(os.Stderr, i18n.T("main.usage"))
|
|
}
|