diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 4f299d4..82e568e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,11 +6,16 @@ use std::io; use std::path::PathBuf; use std::process; +pub mod args; + + use rand::{thread_rng, seq::{SliceRandom, IteratorRandom}}; use clap::Parser; +use crate::args::Args; #[derive(Debug)] enum Error { + BadArguments, NoSentences, MultipleSentences, BadTemplate(String), @@ -27,6 +32,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::NoSentences => write!(f, "no sentences.txt file found"), Error::MultipleSentences => @@ -64,7 +71,7 @@ type ProgResult<T> = Result<T, Error>; #[derive(Parser, Debug)] #[command(name = "spout")] #[command(about = "Generates nonsense", long_about = None)] -struct Args { +struct OldArgs { /// Path to data directory directory: String, @@ -326,7 +333,8 @@ fn crash(e: Error) -> ! { process::exit(1); } -fn sub_main(args: Args) -> ProgResult<()> { +fn sub_main() -> ProgResult<()> { + let args = Args::parse().ok_or(Error::BadArguments)?; let (mut sentences, mut categories) = read_files(&args.directory, args.unique)?; for _i in 0..args.n_sentences { @@ -339,9 +347,7 @@ fn sub_main(args: Args) -> ProgResult<()> { } fn main() { - let args = Args::parse(); - - if let Err(e) = sub_main(args) { + if let Err(e) = sub_main() { crash(e) } } |
