From d626ae08cdfe8d1cbae3fdd0ccc9827d4691718e Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Mon, 20 Nov 2017 03:24:41 -0800 Subject: add profiles command to list known profiles also ... include profile command file, which i neglected to include in a prior commit --- src/commands/fav.rs | 2 +- src/commands/mod.rs | 1 + src/commands/profile.rs | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/commands/profile.rs (limited to 'src/commands') diff --git a/src/commands/fav.rs b/src/commands/fav.rs index 5c12535..e823618 100644 --- a/src/commands/fav.rs +++ b/src/commands/fav.rs @@ -43,7 +43,7 @@ pub static FAV: Command = Command { keyword: "fav", params: 1, exec: fav, - param_str: "", + param_str: " ", help_str: "Favorite a tweet." }; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3404470..262a748 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -23,6 +23,7 @@ pub mod profile; pub static COMMANDS: &[&Command] = &[ &profile::PROFILE, + &profile::PROFILES, &help::HELP, &auth::AUTH, &auth::PIN, diff --git a/src/commands/profile.rs b/src/commands/profile.rs new file mode 100644 index 0000000..c0d5d79 --- /dev/null +++ b/src/commands/profile.rs @@ -0,0 +1,38 @@ +use tw; +use std; +use std::collections::HashMap; +use hyper; +use ::Queryer; + +use commands::Command; + +pub static PROFILE: Command = Command { + keyword: "profile", + params: 1, + exec: switch_profile, + param_str: " ", + help_str: "Switch to profile " +}; + +fn switch_profile(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + let profile_name = line.trim(); + if tweeter.profiles.contains_key(profile_name) { + tweeter.curr_profile = Some(profile_name.to_owned()); + } else { + tweeter.display_info.status(format!("No profile named {}", profile_name)) + }; +} + +pub static PROFILES: Command = Command { + keyword: "profiles", + params: 0, + exec: list_profiles, + param_str: "", + help_str: "List all profiles" +}; + +fn list_profiles(line: String, tweeter: &mut tw::TwitterCache, queryer: &mut Queryer) { + tweeter.display_info.recv(::display::Infos::Text( + tweeter.profiles.keys().map(|key| key.to_owned()).collect() + )); +} -- cgit v1.1