Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
name = "rust_iso3166"
version = "0.1.14"
edition = "2021"
description="ISO 3166-1 (Codes for the representation of names of countries and their subdivisions – Part 1: Country codes) is a standard defining codes for the names of countries, dependent territories, and special areas of geographical interest. It is the first part of the ISO 3166 standard published by the International Organization for Standardization."
repository="https://github.com/rust-iso/rust_iso3166"
license="Apache-2.0"
description = "ISO 3166-1 (Codes for the representation of names of countries and their subdivisions – Part 1: Country codes) is a standard defining codes for the names of countries, dependent territories, and special areas of geographical interest. It is the first part of the ISO 3166 standard published by the International Organization for Standardization."
repository = "https://github.com/rust-iso/rust_iso3166"
license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
exclude = ["src/*.py"]
documentation = "https://docs.rs/rust_iso3166/"
keywords=["ISO3166", "ISO3166-1", "ISO3166-2", "ISO3166-3"]
keywords = ["ISO3166", "ISO3166-1", "ISO3166-2", "ISO3166-3"]

[features]
cli = ["dep:prettytable-rs"]

[[bin]]
name = "main"
path = "src/bin/main.rs"
required-features = ["cli"]

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
phf = { version = "^0.11.1", features = ["macros"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
prettytable-rs = "^0.10"
phf = { version = "^0.13.1", features = ["macros"] }
prettytable-rs = { version = "^0.10", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "^0.2.83"
Expand Down
82 changes: 35 additions & 47 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
#[cfg(not(target_arch = "wasm32"))]
fn main() {
use prettytable::{row, Table};
use std::env;
use prettytable::{row, Table};
use std::env;

let mut args = env::args();
let script_name = match args.next() {
Some(arg) => arg,
None => String::from(""),
};
let query = match args.next() {
Some(arg) => arg,
None => String::from(""),
};
let query = &query.to_lowercase();
let mut args = env::args();
let script_name = args.next().unwrap_or_default();
let query = args.next().unwrap_or_default();
let query = &query.to_lowercase();

eprintln!("Usage: {} [query]", script_name);
let mut found = false;
let mut table = Table::new();
table.add_row(row!["Name", "Alpha2", "Alpha3", "Numeric"]);
eprintln!("Usage: {} [query]", script_name);
let mut found = false;
let mut table = Table::new();
table.add_row(row!["Name", "Alpha2", "Alpha3", "Numeric"]);

for country in rust_iso3166::ALL {
if country.alpha2.to_lowercase().contains(query)
|| country.alpha3.to_lowercase().contains(query)
|| country.numeric_str().to_lowercase().contains(query)
{
table.add_row(row![
country.name,
country.alpha2,
country.alpha3,
country.numeric_str()
]);
found = true;
}
}

if !found {
for country in rust_iso3166::ALL {
if country.name.to_lowercase().contains(query) {
table.add_row(row![
country.name,
country.alpha2,
country.alpha3,
country.numeric_str()
]);
}
if country.alpha2.to_lowercase().contains(query)
|| country.alpha3.to_lowercase().contains(query)
|| country.numeric_str().to_lowercase().contains(query)
{
table.add_row(row![
country.name,
country.alpha2,
country.alpha3,
country.numeric_str()
]);
found = true;
}
}
}
table.printstd();
}

#[cfg(target_arch = "wasm32")]
fn main() {
unimplemented!();
if !found {
for country in rust_iso3166::ALL {
if country.name.to_lowercase().contains(query) {
table.add_row(row![
country.name,
country.alpha2,
country.alpha3,
country.numeric_str()
]);
}
}
}
table.printstd();
}