Skip to content

Commit 0e322fb

Browse files
committed
geocode: skip --index-update if index is up to date; wordsmith usage text & msgs
1 parent 88e8f11 commit 0e322fb

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

src/cmd/geocode.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ geocode options:
108108
[default: 50000]
109109
--timeout <seconds> Timeout for downloading Geonames cities index.
110110
[default: 60]
111-
--languages <lang> The languages to use for the Geonames cities index.
111+
--languages <lang> The languages to use when building the Geonames cities index.
112+
Only used by the 'index-update' subcommand.
112113
The languages are specified as a comma-separated list of ISO 639-1 codes.
113114
[default: en]
114115
--cache-dir <dir> The directory to use for caching the Geonames cities index.
@@ -315,20 +316,30 @@ async fn geocode_main(args: Args) -> CliResult<()> {
315316
load_engine(geocode_index_file.clone().into(), args.flag_progressbar).await?;
316317

317318
if updater.has_updates(&engine).await? {
318-
winfo!("Updates available. Use `qsv geocode index-update` to apply.");
319+
winfo!(
320+
"Updates available at Geonames.org. Use `qsv geocode index-update` to \
321+
update/rebuild the index.\nPlease use this judiciously as Geonames is a \
322+
free service."
323+
);
319324
} else {
320325
winfo!("Geonames index up-to-date.");
321326
}
322327
},
323328
GeocodeSubCmd::IndexUpdate => {
324329
check_index_file(&geocode_index_file)?;
325-
winfo!(
326-
"Updating Geonames index. This will take a while as we need to download \
327-
~200mb of data and rebuild the index..."
328-
);
329-
let engine = updater.build().await?;
330-
engine.dump_to(geocode_index_file.clone(), EngineDumpFormat::Bincode)?;
331-
winfo!("Updates applied: {geocode_index_file}");
330+
let engine =
331+
load_engine(geocode_index_file.clone().into(), args.flag_progressbar).await?;
332+
if updater.has_updates(&engine).await? {
333+
winfo!(
334+
"Updating/Rebuilding Geonames index. This will take a while as we need to \
335+
download ~200mb of data from Geonames and rebuild the index..."
336+
);
337+
let engine = updater.build().await?;
338+
engine.dump_to(geocode_index_file.clone(), EngineDumpFormat::Bincode)?;
339+
winfo!("Updates applied: {geocode_index_file}");
340+
} else {
341+
winfo!("Skipping update. Geonames index is up-to-date.");
342+
}
332343
},
333344
GeocodeSubCmd::IndexLoad => {
334345
// load alternate geocode index file
@@ -351,17 +362,16 @@ async fn geocode_main(args: Args) -> CliResult<()> {
351362
}
352363
},
353364
GeocodeSubCmd::IndexReset => {
354-
// reset geocode index to the default geocode index by deleting the current one
355-
// the load_engine() function will then download the default geocode index
356-
// from the qsv GitHub repo the next time it's called
357-
winfo!("Resetting Geonames index to default...");
365+
// reset geocode index by deleting the current local copy
366+
// and downloading the default geocode index for the current qsv version
367+
winfo!("Resetting Geonames index to default: {geocode_index_file}...");
358368
if Path::new(&geocode_index_file).exists() {
359369
fs::remove_file(&geocode_index_file)?;
360370
}
361-
// loading the engine will download the default geocode index from the qsv GitHub
362-
// repo
371+
// if there's no index file, load_engine will download the default geocode index
372+
// from the qsv GitHub repo
363373
let _ = load_engine(geocode_index_file.clone().into(), true).await?;
364-
winfo!("Default Geonames index file {geocode_index_file} reset.");
374+
winfo!("Default Geonames index file reset to {QSV_VERSION} release.");
365375
},
366376
_ => unreachable!("index_cmd is true, so this is unreachable."),
367377
}
@@ -521,16 +531,14 @@ async fn load_engine(geocode_index_file: PathBuf, show_progress: bool) -> CliRes
521531
// load existing local index
522532
if show_progress {
523533
woutinfo!(
524-
"Loading existing geocode index from {}",
534+
"Loading existing Geonames index from {}",
525535
index_file.display()
526536
);
527537
}
528538
} else {
529539
// initial load, download index file from qsv releases
530540
if show_progress {
531-
woutinfo!(
532-
"No local index found. Downloading geocode index from qsv {QSV_VERSION} release..."
533-
);
541+
woutinfo!("Downloading default Geonames index for qsv {QSV_VERSION} release...");
534542
}
535543
util::download_file(
536544
&format!(

0 commit comments

Comments
 (0)