aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 8c74322..a96f1a5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,11 +9,11 @@ use std::process;
pub mod args;
use rand::{thread_rng, seq::{SliceRandom, IteratorRandom}};
-use crate::args::Args;
+use crate::args::{Args, ArgError, HELP_STR};
#[derive(Debug)]
enum Error {
- BadArguments,
+ BadArguments(ArgError),
NoSentences,
MultipleSentences,
BadTemplate(String),
@@ -30,8 +30,8 @@ enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
- Error::BadArguments =>
- write!(f, "error while parsing arguments"),
+ Error::BadArguments(e) =>
+ write!(f, "Error while parsing arguments: {}\n{}", e, HELP_STR),
Error::NoSentences =>
write!(f, "no sentences.txt file found"),
Error::MultipleSentences =>
@@ -64,6 +64,12 @@ impl From<io::Error> for Error {
}
}
+impl From<ArgError> for Error {
+ fn from(error: ArgError) -> Self {
+ Error::BadArguments(error)
+ }
+}
+
type ProgResult<T> = Result<T, Error>;
#[derive(Debug, Clone)]
@@ -316,7 +322,7 @@ fn crash(e: Error) -> ! {
}
fn sub_main() -> ProgResult<()> {
- let args = Args::parse().ok_or(Error::BadArguments)?;
+ let args = Args::parse()?;
let (mut sentences, mut categories) = read_files(&args.directory, args.unique)?;
for _i in 0..args.n_sentences {