Files
mesh-delivery/modules/mesh-delivery-view/cmd/mesh-delivery-cli/main.go
T
jschoubben 1b6763de0d Serve the rows on a read-only socket and web page, and print them with mesh-delivery-cli (issue 1134)
The command holds no credential: it asks the local socket, which answers only the rows ask.
2026-10-18 19:31:50 +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 = "/run/mesh-delivery-view/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
}