feat: project scaffold, version command, build

This commit is contained in:
2026-06-21 23:30:44 +01:00
parent 04d3b61bb0
commit afad3bf3f1
5 changed files with 49 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
BINARY := emcli
LDFLAGS := -s -w
.PHONY: build test vet
build:
CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/emcli
test:
go test ./...
vet:
go vet ./...
+17
View File
@@ -0,0 +1,17 @@
package main
import (
"fmt"
"os"
"git.dcglab.co.uk/steve/emcli/internal/version"
)
func main() {
if len(os.Args) >= 2 && os.Args[1] == "version" {
fmt.Println(version.String)
return
}
fmt.Fprintln(os.Stderr, "emcli: no command given")
os.Exit(2)
}
+3
View File
@@ -0,0 +1,3 @@
module git.dcglab.co.uk/steve/emcli
go 1.22
+5
View File
@@ -0,0 +1,5 @@
// Package version holds the build version string.
package version
// String is the emcli version. Overridden at release via -ldflags.
var String = "v0.1.0-dev"
+12
View File
@@ -0,0 +1,12 @@
package version
import "testing"
func TestStringIsSemver(t *testing.T) {
if String == "" {
t.Fatal("version.String must not be empty")
}
if String[0] != 'v' {
t.Fatalf("version %q must start with 'v'", String)
}
}