Files
mesh-delivery/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main.go
T
jschoubben d309bb6cef
mesh/merge-gate head d309bb6cef45 merged into trunk 253f464a8155 — pass: builds mesh-delivery-view → shanks; no bus step; every machine composes with the c…
mesh/repo-check head d309bb6cef45 merged into trunk 253f464a8155 — pass: its merge-check.sh passed
mesh/delivery delivered
Put the view's socket in /var/lib/mesh-delivery-view-cli: the node-engine never places a module's directory below /run (issue 1134)
2026-10-19 01:53:11 +02:00

53 lines
1.2 KiB
Go

// Command mesh-delivery-cli is the operator's command for the delivery view (novox/hq ADR 0429 §3). It asks the
// view's local socket for the rows and prints them; it holds no credential and changes nothing.
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"os"
"mesh-delivery-view/internal/view"
)
const defaultSocket = "/var/lib/mesh-delivery-view-cli/cli.sock"
func main() {
socket := os.Getenv("MESH_DELIVERY_SOCKET")
if socket == "" {
socket = defaultSocket
}
os.Exit(run(os.Args[1:], socket, os.Stdout, os.Stderr))
}
func run(args []string, socket string, out, errOut io.Writer) int {
fs := flag.NewFlagSet("mesh-delivery-cli", flag.ContinueOnError)
fs.SetOutput(errOut)
asJSON := fs.Bool("json", false, "print the rows as JSON")
if err := fs.Parse(args); err != nil {
return 2
}
if fs.NArg() > 0 {
fmt.Fprintln(errOut, "mesh-delivery-cli takes no argument: it only shows")
return 2
}
s, err := view.Ask(socket)
if err != nil {
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
return 1
}
if *asJSON {
enc := json.NewEncoder(out)
enc.SetIndent("", " ")
if err := enc.Encode(s); err != nil {
fmt.Fprintln(errOut, "mesh-delivery-cli:", err)
return 1
}
return 0
}
view.Table(out, s)
return 0
}