From a683b67a7e459dffd67ba6321b97b1c3ce263bde Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 10 Nov 2018 02:23:44 -0500 Subject: refactor some stuff out of the cli module --- src/cmd/sync.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/cmd/sync.rs') diff --git a/src/cmd/sync.rs b/src/cmd/sync.rs index 3f80202..9e09289 100644 --- a/src/cmd/sync.rs +++ b/src/cmd/sync.rs @@ -2,9 +2,31 @@ use db; use lastfm; use paths; -pub fn run(username: &str) -> failure::Fallible<()> { +use clap; + +pub struct Options { + username: String, +} + +pub fn subcommand<'a, 'b>() -> clap::App<'a, 'b> { + clap::SubCommand::with_name("sync") + .about("Updates the local copy of track data from last.fm") + .arg( + clap::Arg::with_name("username") + .required(true) + .help("last.fm username to fetch tracks for") + ) +} + +pub fn options<'a>(matches: &clap::ArgMatches<'a>) -> Options { + Options { + username: matches.value_of("username").unwrap().to_string(), + } +} + +pub fn run(options: &Options) -> failure::Fallible<()> { let db = db::DB::new(&paths::db_path()?)?; - let lastfm = lastfm::LastFMClient::new(username)?; + let lastfm = lastfm::LastFMClient::new(&options.username)?; let from = db.most_recent_timestamp()?.map(|x| x + 1); let to_fetch = lastfm.track_count(from)?; -- cgit v1.2.3-54-g00ecf