Skip to content

Commit

Permalink
geocode: add a convenience option to --cities-url
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Oct 20, 2023
1 parent 7dce4d3 commit ab56070
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/cmd/geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ geocode options:
cities15000.zip - population > 15000; ~26k cities
Note that the more cities are included, the larger the local index file will be,
lookup times will be slower, and the search results will be different.
For convenience, if this is set to 500, 1000, 5000 or 15000, it will be
converted to a geonames cities URL.
[default: https://download.geonames.org/export/dump/cities15000.zip]
--force Force update the Geonames cities index. If not set, qsv will check if there
are updates available at Geonames.org before updating the index.
Expand Down Expand Up @@ -596,7 +598,7 @@ fn replace_column_value(
}

pub fn run(argv: &[&str]) -> CliResult<()> {
let args: Args = util::get_args(USAGE, argv)?;
let mut args: Args = util::get_args(USAGE, argv)?;

if args.flag_new_column.is_some() && args.flag_rename.is_some() {
return fail_incorrectusage_clierror!(
Expand All @@ -610,6 +612,21 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
);
}

// if args.flag_cities_url is a number, assume its a geonames cities file ID
// and convert it to a URL
if args.flag_cities_url.parse::<u32>().is_ok() {
let cities_id = args.flag_cities_url;
// ensure its a valid cities_id - 500, 1000, 5000 or 15000
if cities_id != "500" && cities_id != "1000" && cities_id != "5000" && cities_id != "15000"
{
return fail_incorrectusage_clierror!(
"Invalid --cities-url: {cities_id} - must be one of 500, 1000, 5000 or 15000"
);
}
args.flag_cities_url =
format!("https://download.geonames.org/export/dump/cities{cities_id}.zip");
}

if let Err(err) = Url::parse(&args.flag_cities_url) {
return fail_incorrectusage_clierror!(
"Invalid --cities-url: {url} - {err}",
Expand Down

0 comments on commit ab56070

Please sign in to comment.