aboutsummaryrefslogtreecommitdiff
path: root/mountain_pass
diff options
context:
space:
mode:
Diffstat (limited to 'mountain_pass')
-rw-r--r--mountain_pass/cli.go39
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")
+}