Files
vpp-maglev/cmd/maglevc/main.go
Pim van Pelt 74448cf6d0 Guard pause/resume against disabled backends; clean up CLI errors
- PauseBackend and ResumeBackend return an error (not bool) when the
  backend is disabled, preventing an inconsistent state where the
  health state says "paused" but enabled=false.
- DisableBackend and EnableBackend now log uniform backend-transition
  lines with from/to instead of separate backend-disable/backend-enable
  messages.
- CLI errors strip gRPC boilerplate ("rpc error: code = ... desc = ")
  and display the server message in red (when color is enabled). Both
  the interactive shell and one-shot mode use the same formatError path.
2026-04-11 21:19:10 +02:00

55 lines
1.3 KiB
Go

// Copyright (c) 2026, Pim van Pelt <pim@ipng.ch>
package main
import (
"context"
"flag"
"fmt"
"os"
"strings"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
buildinfo "git.ipng.ch/ipng/vpp-maglev/cmd"
"git.ipng.ch/ipng/vpp-maglev/internal/grpcapi"
)
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", formatError(err))
os.Exit(1)
}
}
func run() error {
serverAddr := flag.String("server", "localhost:9090", "maglev server address")
color := flag.Bool("color", true, "colorize static labels in output")
flag.Parse()
colorEnabled = *color
conn, err := grpc.NewClient(*serverAddr,
grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("connect %s: %w", *serverAddr, err)
}
defer conn.Close()
client := grpcapi.NewMaglevClient(conn)
ctx := context.Background()
args := flag.Args()
if len(args) == 0 {
// Interactive shell: announce version on startup.
fmt.Printf("maglevc %s (commit %s, built %s)\n",
buildinfo.Version(), buildinfo.Commit(), buildinfo.Date())
return runShell(ctx, client)
}
// One-shot command from CLI arguments.
root := buildTree()
tokens := splitTokens(strings.Join(args, " "))
return dispatch(ctx, root, client, tokens)
}