From 1e1a47061c455a5324d8a62fa9bcee9ecdf9c4cb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 7 Nov 2018 10:01:18 -0500 Subject: better command line parsing --- src/cli.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/cli.rs (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..4e1d7cb --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,28 @@ +use clap; + +const _DUMMY_DEPENDENCY: &'static str = include_str!("../Cargo.toml"); + +pub struct Options { + pub username: String, + pub api_key: String, +} + +pub fn get_options() -> Options { + let matches = app_from_crate!() + .arg( + clap::Arg::with_name("username") + .required(true) + .help("last.fm username to fetch tracks for") + ) + .arg( + clap::Arg::with_name("api_key") + .required(true) + .help("last.fm api key") + ) + .get_matches(); + + Options { + username: matches.value_of("username").unwrap().to_string(), + api_key: matches.value_of("api_key").unwrap().to_string(), + } +} -- cgit v1.2.3-54-g00ecf