Skip to content

Commit

Permalink
Refractoring rssg to be more readable:
Browse files Browse the repository at this point in the history
	* return process exit 0 for main program and call err in read argument
	* rename read_text function to be more specfic on what it does
	* moved logic in proccess function to 2 distinct funtions
  • Loading branch information
Antonio-Bennett committed Oct 16, 2021
1 parent 98c57d0 commit 239c5ed
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 211 deletions.
15 changes: 8 additions & 7 deletions src/cli/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parsing::input::{finalize_dist, read_text};
use std::{env, error::Error, process};
use crate::parsing::input::{finalize_dist, process_arguments};
use std::{env, error::Error};

pub fn read_arguments() -> Result<(), Box<dyn Error>> {
//Arguments passed to program
Expand All @@ -11,10 +11,12 @@ pub fn read_arguments() -> Result<(), Box<dyn Error>> {
//Do not run the program until input is specified check is here because -v is also arg
//count of 2
if env::args().count() == 2 {
println!("Please enter input. Type rssg --help or -h for more information.");
process::exit(0);
return Err(
"Please enter input. Type rssg --help or -h for more information.".into(),
);
}
if read_text(&args[1..]).is_ok() {

if process_arguments(&args[1..]).is_ok() {
finalize_dist(args)
} else {
Err("Could not read files".into())
Expand All @@ -28,8 +30,7 @@ pub fn read_arguments() -> Result<(), Box<dyn Error>> {
}
_ => {
//No valid flag passed
println!("Please enter a valid flag. Type rssg --help or -h for more information.");
process::exit(0);
Err("Please enter a valid flag. Type rssg --help or -h for more information.".into())
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/cli/program.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::process;

use crate::cli::arguments::read_arguments;

pub fn run() {
//Takes appropriate action based on arguments passed ex. rssg --input
read_arguments().unwrap();
if read_arguments().is_err() {
process::exit(0);
}
}
Loading

0 comments on commit 239c5ed

Please sign in to comment.