commit c76df6dc025f7fb508c020bbd387823311edb2a7
parent a0a27aa9d8e216818a1e5d06a1cb41543f656f2d
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Sun, 15 Sep 2019 11:49:19 -0400
Implement follow subcommand
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/src/follow.rs b/src/follow.rs
@@ -0,0 +1,18 @@
+use clap::ArgMatches;
+
+use std::fs::OpenOptions;
+use std::io::prelude::*;
+use std::path::Path;
+
+use crate::config::Config;
+
+/// Follow new source by writing to the config file.
+pub fn follow(_config: &Config, subcommand: &ArgMatches, config_path: &Path) {
+ let nick = subcommand.value_of("nick").unwrap();
+ let url = subcommand.value_of("url").unwrap();
+ // Appends given source to end of config file.
+ let mut config_file = OpenOptions::new().append(true).open(config_path).unwrap();
+ config_file
+ .write_fmt(format_args!("\n{} = {}", nick, url))
+ .unwrap();
+}
diff --git a/src/main.rs b/src/main.rs
@@ -3,6 +3,7 @@ use clap::{crate_version, App, Arg, SubCommand};
use std::path::Path;
mod config;
+mod follow;
mod timeline;
mod tweet;
use crate::config::Config;
@@ -69,6 +70,7 @@ fn main() {
match command.subcommand() {
("tweet", Some(subcommand)) => tweet::tweet(&config, &subcommand),
("timeline", Some(subcommand)) => timeline::timeline(&config, &subcommand),
+ ("follow", Some(subcommand)) => follow::follow(&config, &subcommand, &config_dir),
_ => {}
}
}