|
|
@ -1,6 +1,6 @@ |
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
use std::fs; |
|
|
|
use std::fs; |
|
|
|
use std::env; |
|
|
|
use std::env; |
|
|
|
|
|
|
|
use clap::{Arg, App};
|
|
|
|
|
|
|
|
|
|
|
|
/// Indicator of where the message should be in fumofile
|
|
|
|
/// Indicator of where the message should be in fumofile
|
|
|
|
pub const MESSAGE_INDICATOR: &str = "!message"; |
|
|
|
pub const MESSAGE_INDICATOR: &str = "!message"; |
|
|
@ -19,25 +19,45 @@ fn process_message(fumofile_contents: &mut String, message: &str) -> String { |
|
|
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
// get command line arguments
|
|
|
|
// get command line arguments
|
|
|
|
let args: Vec<String> = env::args().collect(); |
|
|
|
let matches = App::new("fumosay") |
|
|
|
|
|
|
|
.version("0.2.0") |
|
|
|
|
|
|
|
.author("Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>") |
|
|
|
|
|
|
|
.about("cowsay, but with soft friends") |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("fumo") |
|
|
|
|
|
|
|
.short("f") |
|
|
|
|
|
|
|
.long("fumo") |
|
|
|
|
|
|
|
.value_name("fumofile") |
|
|
|
|
|
|
|
.help("choose another fumofumo to print") |
|
|
|
|
|
|
|
.takes_value(true) |
|
|
|
|
|
|
|
.required(false)) |
|
|
|
|
|
|
|
.arg( |
|
|
|
|
|
|
|
Arg::with_name("message") |
|
|
|
|
|
|
|
.short("m") |
|
|
|
|
|
|
|
.long("message") |
|
|
|
|
|
|
|
.help("set a message to print") |
|
|
|
|
|
|
|
.takes_value(true) |
|
|
|
|
|
|
|
.required(true) |
|
|
|
|
|
|
|
.index(1) |
|
|
|
|
|
|
|
.multiple(true) |
|
|
|
|
|
|
|
).get_matches(); |
|
|
|
|
|
|
|
|
|
|
|
// try to retrieve a message from args
|
|
|
|
// default path to the fumofile
|
|
|
|
if args.len() <= 1 { |
|
|
|
|
|
|
|
// no message was provided
|
|
|
|
|
|
|
|
std::process::exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let clarg_message: &String = &args[1..].join(" "); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// path to the fumofile
|
|
|
|
// grab path to exe
|
|
|
|
let fumofile_default_path: String = format!("./fumofiles/{}",FUMO_DEFAULT); |
|
|
|
let executable_path = env::current_exe().expect("Could not get current exe`s path!"); |
|
|
|
let fumofile_path: &Path = Path::new(&fumofile_default_path); |
|
|
|
// remove the last bit (exe filename)
|
|
|
|
|
|
|
|
let executable_dir = executable_path.parent().expect("Could not get exe`s parent directory !"); |
|
|
|
|
|
|
|
// local path to the default fumofile
|
|
|
|
|
|
|
|
let fumofile_default_path = std::path::Path::new("fumofiles").join(FUMO_DEFAULT); |
|
|
|
|
|
|
|
// add them together
|
|
|
|
|
|
|
|
let fumofile_path = executable_dir.join(fumofile_default_path); |
|
|
|
|
|
|
|
|
|
|
|
// read fumofile
|
|
|
|
// read fumofile
|
|
|
|
let mut fumofile_contents: String = fs::read_to_string(fumofile_path).unwrap(); |
|
|
|
let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!"); |
|
|
|
|
|
|
|
|
|
|
|
// parse the file and get the resulting string
|
|
|
|
// parse the file and get the resulting string
|
|
|
|
let message: String = process_message(&mut fumofile_contents, clarg_message); |
|
|
|
let message: String = process_message(&mut fumofile_contents, matches.value_of("message").unwrap()); |
|
|
|
|
|
|
|
|
|
|
|
println!("{}", message); |
|
|
|
println!("{}", message); |
|
|
|
} |
|
|
|
} |
|
|
|