package main

import (
	"flag"
	"log"
	"net/http"

	"metis/pkg/service"
)

func serveCmd(args []string) {
	fs := flag.NewFlagSet("serve", flag.ExitOnError)
	bindAddr := fs.String("bind", "", "override bind address")
	fs.Parse(args)

	settings := service.FromEnv()
	if *bindAddr != "" {
		settings.BindAddr = *bindAddr
	}
	app, err := service.NewApp(settings)
	if err != nil {
		log.Fatalf("init service: %v", err)
	}
	log.Printf("metis listening on %s", settings.BindAddr)
	if err := http.ListenAndServe(settings.BindAddr, app.Handler()); err != nil {
		log.Fatalf("serve: %v", err)
	}
}
