diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-06 16:40:17 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-06 16:40:17 +0200 |
| commit | db4d2b40895db41ce188549f49a6f277ba95c890 (patch) | |
| tree | 0f9ff048726f6ec030606041eebe808b462ebe7d /main.go | |
| parent | 8e0c55230ef59869bda1ca19ca8697b447d57698 (diff) | |
Split cli.go into per-domain command files
Move each CLI command into its owning package (mountain_pass, ride, web)
with dispatch and usage in main.go; remove the cli package.
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 64 |
1 files changed, 62 insertions, 2 deletions
@@ -3,11 +3,15 @@ package main import ( "database/sql" "flag" + "fmt" "log/slog" + "os" "github.com/grafana/pyroscope-go" - "github.com/martinlehoux/biking_home/cli" "github.com/martinlehoux/biking_home/config" + "github.com/martinlehoux/biking_home/mountain_pass" + "github.com/martinlehoux/biking_home/ride" + "github.com/martinlehoux/biking_home/web" "github.com/martinlehoux/kagamigo/kcore" _ "github.com/mattn/go-sqlite3" ) @@ -31,7 +35,63 @@ func main() { db, err := sql.Open("sqlite3", appConfig.Database.Path) kcore.Expect(err, "failed to open database") defer db.Close() - cli.Run(db, *configFile, appConfig, flag.Args(), *enablePprof) + runCommand(db, *configFile, appConfig, flag.Args(), *enablePprof) +} + +func runCommand(db *sql.DB, configPath string, appConfig config.Config, args []string, enablePprof bool) { + if len(args) == 0 { + web.ServeCmd(db, configPath, appConfig, enablePprof) + return + } + + switch args[0] { + case "fetch-osm": + mountain_pass.FetchOSM() + case "extract-osm": + if len(args) < 2 { + fmt.Fprintln(os.Stderr, "extract-osm requires a PBF file path argument") + printUsage() + os.Exit(2) + } + mountain_pass.ExtractOSM(db, args[1]) + case "backfill": + ride.BackfillCmd(db) + case "backtest": + ride.BacktestCmd(db) + case "elevation": + ride.ElevationCmd(db, args[1:]) + case "serve": + for _, arg := range args[1:] { + if arg == "--pprof" || arg == "-pprof" || arg == "pprof" { + enablePprof = true + } + } + web.ServeCmd(db, configPath, appConfig, enablePprof) + case "help", "-h", "--help": + printUsage() + default: + fmt.Fprintf(os.Stderr, "unknown command %q\n", args[0]) + printUsage() + os.Exit(2) + } +} + +func printUsage() { + fmt.Fprintf(os.Stderr, `Usage: biking_home [global flags] <command> [args] + +Global flags: + -config <path> path to YAML configuration file (default "config.yaml") + -pprof expose pprof endpoints at /debug/pprof (also: "serve --pprof") + +Commands: + serve start web server (default when no command given) + fetch-osm download the France OSM PBF into france-latest.osm.pbf + extract-osm <path> extract mountain passes from an OSM PBF file + backfill recompute all stored ride values + backtest run data benchmarks comparing computed values against stored reference values + elevation analyse detect elevation outliers (tunnel spikes) + elevation fix linearly fix elevation between anchors +`) } // startPyroscope starts the continuous profiler when enabled in the config and |
