aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-04-06 10:24:54 +0100
committerAkshay <[email protected]>2021-04-06 10:24:54 +0100
commitc84c38544bc6e81f0b0482e4e82b6c95848c1a0c (patch)
tree3ae2f3387ba5ef56a7f7c3304dc029ae7845f175 /src/cli.rs
parent3f5b917c6ced370d940774b51ff89cec0d03c562 (diff)
apply clippy lints
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 1dbd098..6357355 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -4,7 +4,7 @@ use std::{
4 path::{Path, PathBuf}, 4 path::{Path, PathBuf},
5}; 5};
6 6
7pub static HELP_TEXT: &'static str = " 7pub static HELP_TEXT: &str = "
8Usage 8Usage
9----- 9-----
10 10
@@ -83,11 +83,11 @@ pub fn parse_args() -> Result<Config, CliError> {
83 if !Path::new(s).is_file() { 83 if !Path::new(s).is_file() {
84 return Err(CliError::FileDoesNotExist); 84 return Err(CliError::FileDoesNotExist);
85 } 85 }
86 return Ok(Config::ExistingProject { 86 Ok(Config::ExistingProject {
87 file_name: PathBuf::from(s), 87 file_name: PathBuf::from(s),
88 }); 88 })
89 } 89 }
90 None => return Ok(Config::Help), 90 None => Ok(Config::Help),
91 }, 91 },
92 _ => Err(CliError::SubCommandParseError), 92 _ => Err(CliError::SubCommandParseError),
93 } 93 }
@@ -104,25 +104,23 @@ fn new_project(args: &mut pico_args::Arguments) -> Result<Config, CliError> {
104 .opt_value_from_fn(["-d", "--dimensions"], parse_dimensions) 104 .opt_value_from_fn(["-d", "--dimensions"], parse_dimensions)
105 .map_err(|_| CliError::DimensionParseError)? 105 .map_err(|_| CliError::DimensionParseError)?
106 .unwrap_or((200, 200)); 106 .unwrap_or((200, 200));
107 return Ok(Config::NewProject { 107 Ok(Config::NewProject {
108 file_name: file_name.ok(), 108 file_name: file_name.ok(),
109 dimensions, 109 dimensions,
110 }); 110 })
111} 111}
112 112
113fn parse_dimensions(input: &str) -> Result<(u32, u32), CliError> { 113fn parse_dimensions(input: &str) -> Result<(u32, u32), CliError> {
114 let dimensions: Vec<&str> = input.split('x').collect(); 114 let dimensions: Vec<&str> = input.split('x').collect();
115 match &dimensions[..] { 115 match &dimensions[..] {
116 [width, height] => { 116 [width, height] => Ok((
117 return Ok(( 117 width
118 width 118 .parse::<u32>()
119 .parse::<u32>() 119 .map_err(|_| CliError::DimensionParseError)?,
120 .map_err(|_| CliError::DimensionParseError)?, 120 height
121 height 121 .parse::<u32>()
122 .parse::<u32>() 122 .map_err(|_| CliError::DimensionParseError)?,
123 .map_err(|_| CliError::DimensionParseError)?, 123 )),
124 )) 124 _ => Err(CliError::DimensionParseError),
125 }
126 _ => return Err(CliError::DimensionParseError),
127 } 125 }
128} 126}