aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/mbf/main.go
diff options
context:
space:
mode:
authormae <mae@maestoso.online>2026-03-04 22:50:58 -0600
committerOphestra <cat@gensokyo.uk>2026-05-02 05:05:56 +0900
commit1d5d063d6a443c9d4a1206d2743e4824411da956 (patch)
treeb32105cf3896f394be91099cfbfb67785de39385 /cmd/mbf/main.go
parente61628a34ecccae0feb5e059a2f808977261fa0e (diff)
cmd/mbf: package status dashboard
This displays package metadata with optional status from a report.
Diffstat (limited to 'cmd/mbf/main.go')
-rw-r--r--cmd/mbf/main.go51
1 files changed, 50 insertions, 1 deletions
diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go
index 0d44bdbc..291e91ef 100644
--- a/cmd/mbf/main.go
+++ b/cmd/mbf/main.go
@@ -20,6 +20,7 @@ import (
"io"
"log"
"net"
+ "net/http"
"os"
"os/signal"
"path/filepath"
@@ -41,6 +42,9 @@ import (
"hakurei.app/internal/pkg"
"hakurei.app/internal/rosa"
"hakurei.app/message"
+
+ "hakurei.app/cmd/mbf/internal/pkgserver"
+ "hakurei.app/cmd/mbf/internal/pkgserver/ui"
)
func main() {
@@ -180,6 +184,7 @@ func main() {
{
var (
+ flagBind string
flagStatus bool
flagReport string
)
@@ -187,9 +192,53 @@ func main() {
"info",
"Display out-of-band metadata of an artifact",
func(args []string) (err error) {
- return commandInfo(&cm, args, os.Stdout, flagStatus, flagReport)
+ const shutdownTimeout = 15 * time.Second
+
+ var r *rosa.Report
+ if flagReport != "" {
+ if r, err = rosa.OpenReport(flagReport); err != nil {
+ return err
+ }
+ defer func() {
+ if closeErr := r.Close(); err == nil {
+ err = closeErr
+ }
+ }()
+ defer r.HandleAccess(&err)()
+ }
+
+ if flagBind == "" {
+ return commandInfo(&cm, args, os.Stdout, flagStatus, r)
+ }
+
+ var mux http.ServeMux
+ ui.Register(&mux)
+ if err = pkgserver.Register(ctx, &mux, r); err != nil {
+ return
+ }
+
+ server := http.Server{Addr: flagBind, Handler: &mux}
+ go func() {
+ <-ctx.Done()
+ cc, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
+ defer cancel()
+ if _err := server.Shutdown(cc); _err != nil {
+ log.Fatal(_err)
+ }
+ }()
+
+ msg.Verbosef("listening on %q", flagBind)
+ err = server.ListenAndServe()
+ if errors.Is(err, http.ErrServerClosed) {
+ err = nil
+ }
+ return
},
).Flag(
+ &flagBind,
+ "bind", command.StringFlag(""),
+ "TCP address for the server to listen on",
+ ).Flag(
&flagStatus,
"status", command.BoolFlag(false),
"Display cure status if available",