- Add `cmd/main.go` with a new `warpbox` root command and `run` subcommand - Support `--addr` flag (default `:8080`) and delegate startup to `server.Run` - Initialize Go module and dependencies (cobra, gin) via `go.mod`/`go.sum` to enable building the new CLI entrypointfeat(cli): add cobra-based CLI to run WarpBox server - Add `cmd/main.go` with a new `warpbox` root command and `run` subcommand - Support `--addr` flag (default `:8080`) and delegate startup to `server.Run` - Initialize Go module and dependencies (cobra, gin) via `go.mod`/`go.sum` to enable building the new CLI entrypoint
40 lines
803 B
Go
40 lines
803 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"warpbox/lib/server"
|
|
)
|
|
|
|
func main() {
|
|
if err := newRootCommand().Execute(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func newRootCommand() *cobra.Command {
|
|
rootCmd := &cobra.Command{
|
|
Use: "warpbox",
|
|
Short: "WarpBox command line interface",
|
|
Long: "WarpBox provides commands for running and managing the WarpBox service.",
|
|
}
|
|
|
|
var addr string
|
|
runCmd := &cobra.Command{
|
|
Use: "run",
|
|
Short: "Run the HTTP server",
|
|
Long: "Run the WarpBox HTTP server. The root endpoint responds with ok.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return server.Run(addr)
|
|
},
|
|
}
|
|
runCmd.Flags().StringVar(&addr, "addr", ":8080", "HTTP server address")
|
|
|
|
rootCmd.AddCommand(runCmd)
|
|
return rootCmd
|
|
}
|