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 /mountain_pass/cli.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 'mountain_pass/cli.go')
| -rw-r--r-- | mountain_pass/cli.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mountain_pass/cli.go b/mountain_pass/cli.go new file mode 100644 index 0000000..ef8dfda --- /dev/null +++ b/mountain_pass/cli.go @@ -0,0 +1,39 @@ +package mountain_pass + +import ( + "context" + "database/sql" + "os" + + "github.com/martinlehoux/kagamigo/kcore" + "github.com/schollz/progressbar/v3" +) + +// ProgressBarEnabled reports whether stderr is attached to a terminal, so the +// progress bar only renders for interactive runs and stays out of piped or +// redirected output. +func ProgressBarEnabled() bool { + fi, err := os.Stderr.Stat() + return err == nil && fi.Mode()&os.ModeCharDevice != 0 +} + +func FetchOSM() { + err := FetchFrancePBF("france-latest.osm.pbf") + kcore.Expect(err, "failed to download France OSM PBF") +} + +func ExtractOSM(db *sql.DB, pbfPath string) { + var bar *progressbar.ProgressBar + _, err := ExtractMountainPasses(context.Background(), pbfPath, db, func(current, total int64) { + if bar == nil && ProgressBarEnabled() { + bar = progressbar.DefaultBytes(total, "Extracting mountain passes") + } + if bar != nil { + bar.Set64(current) + } + }) + if bar != nil { + bar.Finish() + } + kcore.Expect(err, "failed to extract mountain passes from OSM") +} |
