Skip to content

Commit 71787c3

Browse files
committed
refacto declaration of option struct
1 parent 038b3c2 commit 71787c3

File tree

1 file changed

+25
-41
lines changed

1 file changed

+25
-41
lines changed

src/main.rs

+25-41
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ fn run() -> Result<()> {
4545

4646
let matches = app::build_app().get_matches_from(env::args_os());
4747

48-
let excluded: Vec<String> = if let Some(user_ignored) = matches.values_of("exclude") {
49-
user_ignored.map(String::from).collect()
50-
} else {
51-
Vec::new()
52-
};
53-
5448
if matches.is_present("languages") {
5549
let iterator = Language::iter().filter(|x| *x != Language::Unknown);
5650

@@ -60,14 +54,6 @@ fn run() -> Result<()> {
6054
std::process::exit(0);
6155
}
6256

63-
let path = String::from(matches.value_of("input").unwrap());
64-
65-
let ascii_language: Language = if let Some(ascii_language) = matches.value_of("ascii-language")
66-
{
67-
Language::from_str(&ascii_language.to_lowercase()).unwrap()
68-
} else {
69-
Language::Unknown
70-
};
7157
let mut disabled_fields = InfoFieldOn {
7258
..Default::default()
7359
};
@@ -101,14 +87,6 @@ fn run() -> Result<()> {
10187
}
10288
}
10389

104-
let ascii_colors: Vec<String> = if let Some(values) = matches.values_of("ascii-colors") {
105-
values.map(String::from).collect()
106-
} else {
107-
Vec::new()
108-
};
109-
110-
let no_bold = !matches.is_present("no-bold");
111-
11290
let image = if let Some(image_path) = matches.value_of("image") {
11391
Some(image::open(image_path).map_err(|_| Error::ImageLoadError)?)
11492
} else {
@@ -136,28 +114,34 @@ fn run() -> Result<()> {
136114
None
137115
};
138116

139-
let no_merges = matches.is_present("no-merge-commits");
140-
141-
let no_color_blocks = matches.is_present("no-color-blocks");
142-
143-
let number_of_authors: usize = if let Some(value) = matches.value_of("authors-number") {
144-
usize::from_str(value).unwrap()
145-
} else {
146-
3
147-
};
148-
149117
let config = options::Options {
150-
path,
151-
ascii_language,
152-
ascii_colors,
118+
path: String::from(matches.value_of("input").unwrap()),
119+
ascii_language: if let Some(ascii_language) = matches.value_of("ascii-language") {
120+
Language::from_str(&ascii_language.to_lowercase()).unwrap()
121+
} else {
122+
Language::Unknown
123+
},
124+
ascii_colors: if let Some(values) = matches.values_of("ascii-colors") {
125+
values.map(String::from).collect()
126+
} else {
127+
Vec::new()
128+
},
153129
disabled_fields,
154-
no_bold,
155-
image,
130+
no_bold: !matches.is_present("no-bold"),
131+
image: image,
156132
image_backend,
157-
no_merges,
158-
no_color_blocks,
159-
number_of_authors,
160-
excluded,
133+
no_merges: matches.is_present("no-merge-commits"),
134+
no_color_blocks: matches.is_present("no-color-blocks"),
135+
number_of_authors: if let Some(value) = matches.value_of("authors-number") {
136+
usize::from_str(value).unwrap()
137+
} else {
138+
3
139+
},
140+
excluded: if let Some(user_ignored) = matches.values_of("exclude") {
141+
user_ignored.map(String::from).collect()
142+
} else {
143+
Vec::new()
144+
},
161145
};
162146

163147
let info = Info::new(config)?;

0 commit comments

Comments
 (0)