arche / internal/cli/cmd_ui.go

commit 154431fd
 1package cli
 2
 3import (
 4	"fmt"
 5
 6	"arche/internal/ui"
 7
 8	"github.com/spf13/cobra"
 9)
10
11const defaultUIPort = 7070
12
13var uiCmd = &cobra.Command{
14	Use:   "ui",
15	Short: "Launch the local web UI",
16	Long: `Start a local HTTP server serving the Arche web interface.
17
18The interface shows the commit log, file tree, working copy status,
19and bookmarks. The port defaults to 7070 and can be overridden via
20--port or the ui.port setting in .arche/config.toml.
21
22  arche ui               - start on default port (7070)
23  arche ui --port 8080   - start on port 8080`,
24	Args: cobra.NoArgs,
25	RunE: func(cmd *cobra.Command, args []string) error {
26		r := openRepo()
27		defer r.Close()
28
29		port, _ := cmd.Flags().GetInt("port")
30		if port == 0 {
31			port = r.Cfg.UI.Port
32		}
33		if port == 0 {
34			port = defaultUIPort
35		}
36
37		fmt.Printf("arche ui: open http://localhost:%d in your browser\n", port)
38		return ui.Serve(r, port)
39	},
40}
41
42func init() {
43	uiCmd.Flags().Int("port", 0, "port to listen on (default: ui.port from config, or 7070)")
44}