-
-
Save Serentty/32486a5c06605481892b11c90b3adeb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Configuration { | |
wiki_url: String | |
} | |
lazy_static! { | |
static ref CONFIGURATION: Configuration = parse_arguments(); | |
} | |
fn main() { | |
// Parse the arguments (again) to see if a help message needs to be printed | |
parse_arguments(); | |
// Initial setup | |
let mut main = Cursive::default(); | |
// Set theme | |
main.set_theme(theme_gen()); | |
main.add_global_callback('q', |s| s.quit()); | |
main.add_global_callback('s', |s| search(s)); | |
main.run(); | |
} | |
fn parse_arguments() -> Configuration { | |
let matches = App::new("Taizen") | |
.version("0.1.0") | |
.author("NerdyPepper") | |
.about("TUI MediaWiki browser") | |
.arg(Arg::with_name("URL") | |
.help("The URL of the wiki to be viewed") | |
.index(1)) | |
.arg(Arg::with_name("lang") | |
.short("l") | |
.long("lang") | |
.value_name("CODE") | |
.help("Choose the language for Wikipedia") | |
.takes_value(true)) | |
.get_matches(); | |
if matches.is_present("HELP") { | |
std::process::exit(0); | |
} | |
let lang = matches.value_of("lang").unwrap_or("en").to_string(); | |
let wiki_url = matches.value_of("URL").unwrap_or(&format!("https://{}.wikipedia.org", lang)).to_string(); | |
Configuration { | |
wiki_url | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment