Browse Source

Fixed ugly error stack trace when no message was given

main 0.4.3
Unbewohnte 3 years ago
parent
commit
5c81826406
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 13
      src/main.rs

2
Cargo.lock generated

@ -45,7 +45,7 @@ dependencies = [
[[package]] [[package]]
name = "fumosay" name = "fumosay"
version = "0.4.2" version = "0.4.3"
dependencies = [ dependencies = [
"clap", "clap",
] ]

2
Cargo.toml

@ -1,6 +1,6 @@
[package] [package]
name = "fumosay" name = "fumosay"
version = "0.4.2" version = "0.4.3"
edition = "2018" edition = "2018"
authors = ["Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>"] authors = ["Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>"]
description = "Like cowsay, but with soft friends" description = "Like cowsay, but with soft friends"

13
src/main.rs

@ -22,7 +22,7 @@ fn process_message(fumofile_contents: &mut String, message: &str) -> String {
fn main() { fn main() {
// get command line arguments // get command line arguments
let matches = App::new("fumosay") let matches = App::new("fumosay")
.version("0.4.2") .version("0.4.3")
.author("Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>") .author("Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>")
.about("cowsay, but with soft friends") .about("cowsay, but with soft friends")
.arg( .arg(
@ -91,8 +91,10 @@ fn main() {
fs::read_to_string(fumofile_path).expect("Could not find a fumofile!"); fs::read_to_string(fumofile_path).expect("Could not find a fumofile!");
// process the message // process the message
let message_values = matches.values_of("message").expect("No message provided"); let message = matches.values_of("message");
let message_vec: Vec<&str> = message_values.collect(); match message {
Some(messages) => {
let message_vec: Vec<&str> = messages.collect();
let joined_message = message_vec.join(" "); let joined_message = message_vec.join(" ");
// parse the file, insert fiven message and get the resulting string // parse the file, insert fiven message and get the resulting string
@ -100,3 +102,8 @@ fn main() {
println!("{}", fumosay); println!("{}", fumosay);
} }
None => {
print!("{}", matches.usage())
}
}
}

Loading…
Cancel
Save