diff --git a/Makefile b/Makefile index 81206b6..10c0e1f 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ FRONTEND_WEB_SRC := $(shell find cmd/frontend/web/src -type f 2>/dev/null) \ FRONTEND_WEB_DIST := cmd/frontend/web/dist/index.html NATIVE_ARCH := $(shell go env GOARCH) -VERSION := 0.9.5 +VERSION := 1.0.0 COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS := -X '$(MODULE)/cmd.version=$(VERSION)' \ @@ -60,22 +60,22 @@ all: build build: $(GEN_FILES) $(FRONTEND_WEB_DIST) mkdir -p build/$(NATIVE_ARCH) - go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/maglevd ./cmd/maglevd/ - go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/maglevc ./cmd/maglevc/ + go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/maglevd ./cmd/server/ + go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/maglevc ./cmd/client/ go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/maglevd-frontend ./cmd/frontend/ go build -ldflags "$(LDFLAGS)" -o build/$(NATIVE_ARCH)/maglevt ./cmd/tester/ build-amd64: $(GEN_FILES) $(FRONTEND_WEB_DIST) mkdir -p build/amd64 - GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/maglevd ./cmd/maglevd/ - GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/maglevc ./cmd/maglevc/ + GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/maglevd ./cmd/server/ + GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/maglevc ./cmd/client/ GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/maglevd-frontend ./cmd/frontend/ GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o build/amd64/maglevt ./cmd/tester/ build-arm64: $(GEN_FILES) $(FRONTEND_WEB_DIST) mkdir -p build/arm64 - GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/maglevd ./cmd/maglevd/ - GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/maglevc ./cmd/maglevc/ + GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/maglevd ./cmd/server/ + GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/maglevc ./cmd/client/ GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/maglevd-frontend ./cmd/frontend/ GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o build/arm64/maglevt ./cmd/tester/ diff --git a/README.md b/README.md index 72ec682..5ce978b 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ doesn't kill the daemon; `SIGTERM` / `SIGINT` remain the clean shutdown signals. Every flag on every binary also has an environment-variable -equivalent (e.g. `MAGLEV_CONFIG`, `MAGLEV_GRPC_ADDR`, +equivalent (e.g. `MAGLEV_CONFIG`, `MAGLEV_GRPC_ADDR`, `MAGLEV_SERVER`, `MAGLEV_SERVERS`, `MAGLEV_LISTEN`, `MAGLEV_LOG_LEVEL`) so all three programs can be driven entirely via env in containerized deployments. diff --git a/cmd/maglevc/color.go b/cmd/client/color.go similarity index 100% rename from cmd/maglevc/color.go rename to cmd/client/color.go diff --git a/cmd/maglevc/commands.go b/cmd/client/commands.go similarity index 100% rename from cmd/maglevc/commands.go rename to cmd/client/commands.go diff --git a/cmd/maglevc/complete.go b/cmd/client/complete.go similarity index 100% rename from cmd/maglevc/complete.go rename to cmd/client/complete.go diff --git a/cmd/maglevc/main.go b/cmd/client/main.go similarity index 81% rename from cmd/maglevc/main.go rename to cmd/client/main.go index dac0e0c..071a534 100644 --- a/cmd/maglevc/main.go +++ b/cmd/client/main.go @@ -24,10 +24,21 @@ func main() { } func run() error { - serverAddr := flag.String("server", "localhost:9090", "maglev server address") + defaultServer := "localhost:9090" + if v := os.Getenv("MAGLEV_SERVER"); v != "" { + defaultServer = v + } + serverAddr := flag.String("server", defaultServer, "maglev server address (env: MAGLEV_SERVER)") color := flag.Bool("color", true, "colorize static labels in output (defaults to false in one-shot mode)") + printVersion := flag.Bool("version", false, "print version and exit") flag.Parse() + if *printVersion { + fmt.Printf("maglevc %s (commit %s, built %s)\n", + buildinfo.Version(), buildinfo.Commit(), buildinfo.Date()) + return nil + } + // Detect whether -color was explicitly set so we can pick a // mode-aware default: color is useful in the interactive shell but // noise (ANSI escapes) when piping one-shot output into scripts. diff --git a/cmd/maglevc/shell.go b/cmd/client/shell.go similarity index 100% rename from cmd/maglevc/shell.go rename to cmd/client/shell.go diff --git a/cmd/maglevc/tree.go b/cmd/client/tree.go similarity index 100% rename from cmd/maglevc/tree.go rename to cmd/client/tree.go diff --git a/cmd/maglevc/tree_test.go b/cmd/client/tree_test.go similarity index 100% rename from cmd/maglevc/tree_test.go rename to cmd/client/tree_test.go diff --git a/cmd/maglevc/watch.go b/cmd/client/watch.go similarity index 100% rename from cmd/maglevc/watch.go rename to cmd/client/watch.go diff --git a/cmd/maglevd/main.go b/cmd/server/main.go similarity index 100% rename from cmd/maglevd/main.go rename to cmd/server/main.go diff --git a/docs/design.md b/docs/design.md index 22c43b3..02f458c 100644 --- a/docs/design.md +++ b/docs/design.md @@ -4,7 +4,7 @@ | | | | --- | --- | -| **Status** | Retrofit — describes shipped behavior as of `v0.9.5` | +| **Status** | Retrofit — describes shipped behavior as of `v1.0.0` | | **Author** | Pim van Pelt `` | | **Last updated** | 2026-04-15 | | **Audience** | Operators and contributors who will read the source tree next | diff --git a/docs/maglevc.1 b/docs/maglevc.1 index b597cb1..40b590b 100644 --- a/docs/maglevc.1 +++ b/docs/maglevc.1 @@ -28,13 +28,14 @@ Type .B ? at any point to list completions without advancing the input. .SH OPTIONS +Flags may also be supplied via an environment variable (shown in +parentheses where applicable); the flag takes precedence. .TP .BI \-server " addr" Address of the .B maglevd gRPC server. -(default: -.IR localhost:9090 ) +.RI "(default: " localhost:9090 "; env: " MAGLEV_SERVER ) .TP .BR \-color [=\fIbool\fR] Colorize static field labels in output using ANSI dark blue. The @@ -45,6 +46,9 @@ or files stays free of escape codes. Pass or .B \-color=false explicitly to override the default for either mode. +.TP +.B \-version +Print version, commit hash, and build date, then exit. .SH EXAMPLES Open the interactive shell (no command on the command line). Tab completes the current token; typing diff --git a/docs/user-guide.md b/docs/user-guide.md index 34118f1..7911b9f 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -233,10 +233,11 @@ interactive shell. maglevc [--server host:port] [--color[=bool]] [command...] ``` -| Flag | Default | Description | -|---|---|---| -| `--server` | `localhost:9090` | Address of the `maglevd` gRPC server. | -| `--color` | mode-aware | Colorize static field labels (dark blue ANSI). Defaults to `true` in the interactive shell and `false` in one-shot mode, so output piped into scripts stays free of escape codes. Pass `--color=true` or `--color=false` explicitly to override either default. | +| Flag | Environment variable | Default | Description | +|---|---|---|---| +| `--server` | `MAGLEV_SERVER` | `localhost:9090` | Address of the `maglevd` gRPC server. The flag takes precedence over the env var. | +| `--color` | — | mode-aware | Colorize static field labels (dark blue ANSI). Defaults to `true` in the interactive shell and `false` in one-shot mode, so output piped into scripts stays free of escape codes. Pass `--color=true` or `--color=false` explicitly to override either default. | +| `--version` | — | — | Print version, commit hash, and build date, then exit. | When `command` arguments are supplied the command is executed and `maglevc` exits; in this mode ANSI color is off by default so the output is script-safe. diff --git a/internal/vpp/client.go b/internal/vpp/client.go index cca610a..2736fcc 100644 --- a/internal/vpp/client.go +++ b/internal/vpp/client.go @@ -95,7 +95,7 @@ func (c *Client) getStateSource() StateSource { // New creates a Client for the given socket paths. The warmup tracker's // clock starts here — the restart-neutrality window is measured from the // moment the Client is constructed, which in practice is a few tens of -// milliseconds after process start (see cmd/maglevd/main.go startup +// milliseconds after process start (see cmd/server/main.go startup // sequence). If main.go ever grows a long-running initialisation step // before vpp.New(), the warmup clock should be moved accordingly. func New(apiAddr, statsAddr string) *Client {