Added detecting what mode we're in

This commit is contained in:
Maddox Werts 2025-04-18 18:25:50 -04:00
parent 977c9b5ce3
commit 2555c31e92

View file

@ -1,10 +1,19 @@
// Libraries // Libraries
use clap::{Arg, ArgAction, Command}; use clap::{Arg, ArgAction, Command};
// Enums
pub enum ArgModes {
Convert,
Package,
}
// Structures // Structures
pub struct Arguments { pub struct Arguments {
pub mode: ArgModes,
pub file_input: String, pub file_input: String,
pub file_output: String, pub file_output: String,
pub csv_directory: String,
} }
// Implementations // Implementations
@ -55,14 +64,48 @@ impl Arguments {
) )
.get_matches(); .get_matches();
// Getting the required arguments // Getting required arguments
let file_input = matches.get_one::<String>("file_in").unwrap().to_string(); let mode: ArgModes;
let file_output = matches.get_one::<String>("file_out").unwrap().to_string();
let file_input: String;
let file_output: String;
let csv_directory: String;
// Getting the mode being run
match matches.subcommand() {
Some(("convert", convert_matches)) => {
mode = ArgModes::Convert;
file_input = convert_matches
.get_one::<String>("file_in")
.unwrap()
.to_owned();
file_output = convert_matches
.get_one::<String>("file_out")
.unwrap()
.to_owned();
csv_directory = String::new();
}
Some(("package", package_matches)) => {
mode = ArgModes::Package;
csv_directory = package_matches
.get_one::<String>("directory")
.unwrap()
.to_owned();
file_input = String::new();
file_output = String::new();
}
_ => unreachable!(),
}
// Returning a Result // Returning a Result
Self { Self {
mode,
file_input, file_input,
file_output, file_output,
csv_directory,
} }
} }
} }