From a9b5f7be4e98ecaa016382d3024270192ee586b0 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 7 Dec 2022 21:58:05 +0100 Subject: added --version; cargo update --- src/input.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/input.rs') diff --git a/src/input.rs b/src/input.rs index b2b4f1b..41b0c29 100644 --- a/src/input.rs +++ b/src/input.rs @@ -11,6 +11,7 @@ pub struct Input { pub delete_old: bool, pub clean: bool, pub disable_download: bool, + pub version: bool, } impl Input { @@ -22,6 +23,7 @@ impl Input { let mut delete_old = false; let mut clean = false; let mut disable_download = false; + let mut version = false; let mut toremove: Vec = vec![]; for (i, input) in split.clone().into_iter().enumerate() { @@ -32,6 +34,7 @@ impl Input { "--delete-old" => delete_old = true, "--clean" => clean = true, "--disable-download" => disable_download = true, + "--version" => version = true, _ => continue, } toremove.push(i) @@ -41,6 +44,11 @@ impl Input { for rem in toremove.into_iter().rev() { split.remove(rem); } + + if version { + println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); + std::process::exit(0); + } let command = Cmd::from(split.remove(0))?; let subcommand = match split.is_empty() { @@ -59,7 +67,7 @@ impl Input { } }; - Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean, disable_download }) + Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean, disable_download, version }) } } @@ -110,7 +118,7 @@ pub async fn get_input(config: Cfg) -> Result<(), Box> { args.reverse(); args.pop(); args.reverse(); - + let input = Input::from(&args.join(" "))?; match input.command { @@ -135,11 +143,10 @@ pub async fn get_input(config: Cfg) -> Result<(), Box> { #[test] fn input_from() { let string = "list add test 1.19.2 fabric"; - let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false, disable_download: false }; + let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false, disable_download: false, version: false }; assert_eq!(Input::from(string).unwrap(), input); let string = "update --direct-download --delete-old"; - let input = Input{ command: Cmd::Update, subcommand: None, args: None, direct_download: true, all_lists: false, clean: false, delete_old: true, disable_download: false }; + let input = Input{ command: Cmd::Update, subcommand: None, args: None, direct_download: true, all_lists: false, clean: false, delete_old: true, disable_download: false, version: false }; assert_eq!(Input::from(string).unwrap(), input); - } -- cgit v1.2.3