diff --git a/fumofiles/fumo.fumo b/fumofiles/fumo.fumo index 643b57f..d329fa8 100644 --- a/fumofiles/fumo.fumo +++ b/fumofiles/fumo.fumo @@ -1,6 +1,5 @@ - __________ -( !message ) - ---------- +(!message) () - () - \(ᗜˬᗜ)/ \ No newline at end of file + () + () + \(ᗜˬᗜ)/ \ No newline at end of file diff --git a/src/fumo.rs b/src/fumo.rs index ddfc1e3..3bba2e9 100644 --- a/src/fumo.rs +++ b/src/fumo.rs @@ -1,8 +1,14 @@ +/// Indicator of where the message should be in fumofile pub const MESSAGE_INDICATOR: &str = "!message"; +/// Fumofile name of the default fumo +pub const FUMO_DEFAULT: &str = "fumo.fumo"; -pub fn sayify(fumofile: &mut String, message: &str) -> String { - if fumofile.contains(MESSAGE_INDICATOR) { - return fumofile.replace(MESSAGE_INDICATOR,message); +/// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given +/// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the +/// `message` will be added on the new line at the end of the fumofile. +pub fn sayify(fumofile_contents: &mut String, message: &str) -> String { + if fumofile_contents.contains(MESSAGE_INDICATOR) { + return fumofile_contents.replace(MESSAGE_INDICATOR,message); } - return format!("{}\n{}", fumofile, message); + return format!("{}\n{}", fumofile_contents, message); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4bb9296..014816c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,31 @@ mod fumo; + +use std::path::Path; +use std::fs; +use std::env; + fn main() { - let mut fumofile_contents = std::fs::read_to_string(std::path::Path::new("./fumofiles/fumo.fumo")).unwrap(); - let message: String = fumo::sayify(&mut fumofile_contents,"fumo"); + // get command line arguments + let args: Vec = env::args().collect(); + + // try to retrieve a message from args + if args.len() <= 1 { + // no message was provided + std::process::exit(1); + } + + let clarg_message = &args[1..].join(" "); + + // path to the fumofile + let fumofile_default_path = format!("./fumofiles/{}",fumo::FUMO_DEFAULT); + let fumofile_path = Path::new(&fumofile_default_path); + + // read fumofile + let mut fumofile_contents = fs::read_to_string(fumofile_path).unwrap(); + + // parse the file and get the resulting string + let message: String = fumo::sayify(&mut fumofile_contents, clarg_message); + println!("{}", message); }