From 2555c31e925490c65cfc548e505cd2f3d0ca8415 Mon Sep 17 00:00:00 2001 From: OBJNULL Date: Fri, 18 Apr 2025 18:25:50 -0400 Subject: [PATCH] Added detecting what mode we're in --- project/src/args.rs | 49 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/project/src/args.rs b/project/src/args.rs index 1a49a2f..90dca94 100644 --- a/project/src/args.rs +++ b/project/src/args.rs @@ -1,10 +1,19 @@ // Libraries use clap::{Arg, ArgAction, Command}; +// Enums +pub enum ArgModes { + Convert, + Package, +} + // Structures pub struct Arguments { + pub mode: ArgModes, + pub file_input: String, pub file_output: String, + pub csv_directory: String, } // Implementations @@ -55,14 +64,48 @@ impl Arguments { ) .get_matches(); - // Getting the required arguments - let file_input = matches.get_one::("file_in").unwrap().to_string(); - let file_output = matches.get_one::("file_out").unwrap().to_string(); + // Getting required arguments + let mode: ArgModes; + + 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::("file_in") + .unwrap() + .to_owned(); + file_output = convert_matches + .get_one::("file_out") + .unwrap() + .to_owned(); + csv_directory = String::new(); + } + Some(("package", package_matches)) => { + mode = ArgModes::Package; + + csv_directory = package_matches + .get_one::("directory") + .unwrap() + .to_owned(); + file_input = String::new(); + file_output = String::new(); + } + _ => unreachable!(), + } // Returning a Result Self { + mode, + file_input, file_output, + csv_directory, } } }