From 5548c9f4a234db1819cf912d42664b5eb83c2de9 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 24 Apr 2024 20:40:47 +0200 Subject: Format with rustfmt --- src/args.rs | 87 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 38 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 3cd9d8a..31bd470 100644 --- a/src/args.rs +++ b/src/args.rs @@ -93,17 +93,19 @@ pub struct Arguments { } pub trait Parser { - fn run(&self, options: &mut Options, args: impl IntoIterator) -> Result; + fn run( + &self, + options: &mut Options, + args: impl IntoIterator, + ) -> Result; fn print_help(&self, options: &Options); } #[allow(dead_code)] -pub struct LongOnlyParser { -} +pub struct LongOnlyParser {} #[allow(dead_code)] -pub struct ShortAndLongParser { -} +pub struct ShortAndLongParser {} fn print_list(list: Vec<(String, &str)>) { let mut left_len: usize = 0; @@ -118,12 +120,16 @@ fn print_list(list: Vec<(String, &str)>) { #[allow(dead_code)] impl LongOnlyParser { pub fn new() -> LongOnlyParser { - LongOnlyParser { } + LongOnlyParser {} } } impl Parser for LongOnlyParser { - fn run(&self, options: &mut Options, args: impl IntoIterator) -> Result { + fn run( + &self, + options: &mut Options, + args: impl IntoIterator, + ) -> Result { let mut ret = Vec::new(); let mut args_iter = args.into_iter(); let program = args_iter.next(); @@ -134,7 +140,7 @@ impl Parser for LongOnlyParser { while let Some(arg) = args_iter.next() { ret.push(arg) } - break + break; } let start = 1; let name; @@ -151,22 +157,22 @@ impl Parser for LongOnlyParser { match option.value_req { ValueRequirement::None => { if value.is_some() { - return Err(format!("option '{}' doesn't allow an argument", arg)) + return Err(format!("option '{}' doesn't allow an argument", arg)); } - }, + } ValueRequirement::Required(_) => { if value.is_none() { value = args_iter.next(); if value.is_none() { - return Err(format!("option '{}' requires an argument", arg)) + return Err(format!("option '{}' requires an argument", arg)); } } - }, - ValueRequirement::Optional(_) => {}, + } + ValueRequirement::Optional(_) => {} } option.set(value); } else { - return Err(format!("unrecognized option '{}'", arg)) + return Err(format!("unrecognized option '{}'", arg)); } } else { ret.push(arg) @@ -193,12 +199,16 @@ impl Parser for LongOnlyParser { #[allow(dead_code)] impl ShortAndLongParser { pub fn new() -> ShortAndLongParser { - ShortAndLongParser { } + ShortAndLongParser {} } } impl Parser for ShortAndLongParser { - fn run(&self, options: &mut Options, args: impl IntoIterator) -> Result { + fn run( + &self, + options: &mut Options, + args: impl IntoIterator, + ) -> Result { let mut ret = Vec::new(); let mut args_iter = args.into_iter(); let program = args_iter.next(); @@ -209,7 +219,7 @@ impl Parser for ShortAndLongParser { while let Some(arg) = args_iter.next() { ret.push(arg) } - break + break; } let start = 2; let name; @@ -226,22 +236,22 @@ impl Parser for ShortAndLongParser { match option.value_req { ValueRequirement::None => { if value.is_some() { - return Err(format!("option '{}' doesn't allow an argument", arg)) + return Err(format!("option '{}' doesn't allow an argument", arg)); } - }, + } ValueRequirement::Required(_) => { if value.is_none() { value = args_iter.next(); if value.is_none() { - return Err(format!("option '{}' requires an argument", arg)) + return Err(format!("option '{}' requires an argument", arg)); } } - }, - ValueRequirement::Optional(_) => {}, + } + ValueRequirement::Optional(_) => {} } option.set(value); } else { - return Err(format!("unrecognized option '{}'", arg)) + return Err(format!("unrecognized option '{}'", arg)); } } else if arg.starts_with("-") && arg.len() > 1 { for c in arg.get(1..).unwrap().chars() { @@ -249,18 +259,18 @@ impl Parser for ShortAndLongParser { let ref mut option = options.options[*index]; let mut value = None; match option.value_req { - ValueRequirement::None => {}, + ValueRequirement::None => {} ValueRequirement::Required(_) => { value = args_iter.next(); if value.is_none() { - return Err(format!("option requires an argument -- '{}", c)) + return Err(format!("option requires an argument -- '{}", c)); } - }, - ValueRequirement::Optional(_) => {}, + } + ValueRequirement::Optional(_) => {} } option.set(value); } else { - return Err(format!("invalid option -- '{}'", c)) + return Err(format!("invalid option -- '{}'", c)); } } } else { @@ -277,25 +287,26 @@ impl Parser for ShortAndLongParser { if option.short() == '\0' { left = match option.value_req { ValueRequirement::None => format!(" --{}", option.long()), - ValueRequirement::Required(name) => - format!(" --{}={}", option.long(), name), - ValueRequirement::Optional(name) => - format!(" --{}[={}]", option.long(), name), + ValueRequirement::Required(name) => format!(" --{}={}", option.long(), name), + ValueRequirement::Optional(name) => { + format!(" --{}[={}]", option.long(), name) + } }; } else if option.long() == "" { left = match option.value_req { ValueRequirement::None => format!("-{}", option.short()), ValueRequirement::Required(name) => format!("-{}={}", option.short(), name), - ValueRequirement::Optional(name) => - format!("-{}[={}]", option.short(), name), + ValueRequirement::Optional(name) => format!("-{}[={}]", option.short(), name), }; } else { left = match option.value_req { ValueRequirement::None => format!("-{}, --{}", option.short(), option.long()), - ValueRequirement::Required(name) => - format!("-{}, --{}={}", option.short(), option.long(), name), - ValueRequirement::Optional(name) => - format!("-{}, --{}[={}]", option.short(), option.long(), name), + ValueRequirement::Required(name) => { + format!("-{}, --{}={}", option.short(), option.long(), name) + } + ValueRequirement::Optional(name) => { + format!("-{}, --{}[={}]", option.short(), option.long(), name) + } }; } lines.push((left, option.description())); -- cgit v1.2.3-70-g09d2