Skip to content

Commit 4761134

Browse files
committed
last one
1 parent a72018a commit 4761134

File tree

3 files changed

+63
-29
lines changed

3 files changed

+63
-29
lines changed

src/cli.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub struct InfoCliOptions {
6767
#[arg(long, value_name = "NUM")]
6868
pub number_of_languages: Option<usize>,
6969
/// Maximum NUM of file churns to be shown
70-
#[arg(long, default_value_t = 3usize, value_name = "NUM")]
71-
pub number_of_file_churns: usize,
70+
#[arg(long, value_name = "NUM")]
71+
pub number_of_file_churns: Option<usize>,
7272
/// Minimum NUM of commits from HEAD used to compute the churn summary
7373
///
7474
/// By default, the actual value is non-deterministic due to time-based computation
@@ -89,7 +89,7 @@ pub struct InfoCliOptions {
8989
pub no_bots: Option<MyRegex>,
9090
/// Ignores merge commits
9191
#[arg(long)]
92-
pub no_merges: bool,
92+
pub no_merges: Option<bool>,
9393
/// Show the email address of each author
9494
#[arg(long, short = 'E')]
9595
pub email: bool,
@@ -101,7 +101,7 @@ pub struct InfoCliOptions {
101101
pub hide_token: bool,
102102
/// Count hidden files and directories
103103
#[arg(long)]
104-
pub include_hidden: bool,
104+
pub include_hidden: Option<bool>,
105105
/// Filters output by language type
106106
#[arg(
107107
long,
@@ -147,7 +147,7 @@ pub struct AsciiCliOptions {
147147
///
148148
/// If set to auto: true color will be enabled if supported by the terminal
149149
#[arg(long, default_value = "auto", value_name = "WHEN", value_enum)]
150-
pub true_color: When,
150+
pub true_color: Option<When>,
151151
}
152152

153153
#[derive(Clone, Debug, Args, PartialEq, Eq)]
@@ -191,13 +191,13 @@ pub struct TextFormattingCliOptions {
191191
pub text_colors: Vec<u8>,
192192
/// Use ISO 8601 formatted timestamps
193193
#[arg(long, short = 'z')]
194-
pub iso_time: bool,
194+
pub iso_time: Option<bool>,
195195
/// Which thousands SEPARATOR to use
196-
#[arg(long, value_name = "SEPARATOR", default_value = "plain", value_enum)]
197-
pub number_separator: NumberSeparator,
196+
#[arg(long, value_name = "SEPARATOR", value_enum)]
197+
pub number_separator: Option<NumberSeparator>,
198198
/// Turns off bold formatting
199199
#[arg(long)]
200-
pub no_bold: bool,
200+
pub no_bold: Option<bool>,
201201
}
202202
#[derive(Clone, Debug, Args, PartialEq, Eq, Default)]
203203
#[command(next_help_heading = "VISUALS")]
@@ -212,7 +212,7 @@ pub struct VisualsCliOptions {
212212
///
213213
/// Replaces language chips with Nerd Font icons
214214
#[arg(long)]
215-
pub nerd_fonts: bool,
215+
pub nerd_fonts: Option<bool>,
216216
}
217217

218218
#[derive(Clone, Debug, Args, PartialEq, Eq)]
@@ -270,7 +270,7 @@ impl Default for InfoCliOptions {
270270
InfoCliOptions {
271271
number_of_authors: Some(3),
272272
number_of_languages: Some(6),
273-
number_of_file_churns: 3,
273+
number_of_file_churns: Some(3),
274274
churn_pool_size: Option::default(),
275275
exclude: Vec::default(),
276276
no_bots: Option::default(),
@@ -291,7 +291,7 @@ impl Default for TextFormattingCliOptions {
291291
TextFormattingCliOptions {
292292
text_colors: Default::default(),
293293
iso_time: Default::default(),
294-
number_separator: NumberSeparator::Plain,
294+
number_separator: Some(NumberSeparator::Plain),
295295
no_bold: Default::default(),
296296
}
297297
}
@@ -303,7 +303,7 @@ impl Default for AsciiCliOptions {
303303
ascii_input: Option::default(),
304304
ascii_colors: Vec::default(),
305305
ascii_language: Option::default(),
306-
true_color: When::Auto,
306+
true_color: Some(When::Auto),
307307
}
308308
}
309309
}
@@ -418,7 +418,7 @@ mod test {
418418
input: PathBuf::from("/tmp/folder"),
419419
info: InfoCliOptions {
420420
number_of_authors: 4,
421-
no_merges: true,
421+
no_merges: Some(true),
422422
disabled_fields: vec![InfoType::Version, InfoType::URL].into(),
423423
..Default::default()
424424
},

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct ConfigOptions {
2121
#[serde(default)]
2222
pub number_of_languages: usize,
2323
#[serde(default)]
24-
pub churn_pool_size: usize,
24+
pub number_of_file_churns: usize,
2525
#[serde(default)]
2626
pub no_merges: bool,
2727
#[serde(default)]
@@ -45,11 +45,11 @@ impl Default for ConfigOptions {
4545
no_title: false,
4646
number_of_authors: 3usize,
4747
number_of_languages: 6usize,
48-
churn_pool_size: 3usize,
48+
number_of_file_churns: 3usize,
4949
no_merges: false,
5050
include_hidden: false,
5151
iso_time: false,
52-
number_separator: NumberSeparator::Plain,
52+
number_separator: NumberSeparator::default(),
5353
no_bold: false,
5454
true_color: When::Auto,
5555
nerd_fonts: false,

src/info/mod.rs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
127127
let loc_by_language_sorted_handle = std::thread::spawn({
128128
let globs_to_exclude = cli_options.info.exclude.clone();
129129
let language_types = cli_options.info.r#type.clone();
130-
let include_hidden = cli_options.info.include_hidden;
130+
let include_hidden = cli_options
131+
.info
132+
.include_hidden
133+
.unwrap_or(config_options.include_hidden);
131134
let workdir = repo_path.clone();
132135
move || {
133136
langs::get_loc_by_language_sorted(
@@ -154,9 +157,17 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
154157
&repo,
155158
cli_options.info.no_bots.clone(),
156159
cli_options.info.churn_pool_size,
157-
cli_options.info.no_merges,
160+
cli_options
161+
.info
162+
.no_merges
163+
.unwrap_or(config_options.no_merges),
158164
)?;
159-
let true_color = match cli_options.ascii.true_color {
165+
let true_color = match cli_options
166+
.ascii
167+
.true_color
168+
.clone()
169+
.unwrap_or(config_options.true_color.clone())
170+
{
160171
When::Always => true,
161172
When::Never => false,
162173
When::Auto => is_truecolor_terminal(),
@@ -170,9 +181,18 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
170181
);
171182

172183
let text_colors = TextColors::new(&cli_options.text_formatting.text_colors, ascii_colors[0]);
173-
let no_bold = cli_options.text_formatting.no_bold;
174-
let number_separator = cli_options.text_formatting.number_separator;
175-
let iso_time = cli_options.text_formatting.iso_time;
184+
let no_bold = cli_options
185+
.text_formatting
186+
.no_bold
187+
.unwrap_or(config_options.no_bold);
188+
let number_separator = cli_options
189+
.text_formatting
190+
.number_separator
191+
.unwrap_or(config_options.number_separator);
192+
let iso_time = cli_options
193+
.text_formatting
194+
.iso_time
195+
.unwrap_or(config_options.iso_time);
176196
let number_of_languages_to_display = cli_options
177197
.info
178198
.number_of_languages
@@ -182,9 +202,16 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
182202
.info
183203
.number_of_authors
184204
.unwrap_or(config_options.number_of_authors);
185-
let number_of_file_churns_to_display = cli_options.info.number_of_file_churns;
205+
let number_of_file_churns_to_display = cli_options
206+
.info
207+
.number_of_file_churns
208+
.unwrap_or(config_options.number_of_file_churns);
186209
let globs_to_exclude = &cli_options.info.exclude;
187210
let show_email = cli_options.info.email;
211+
let nerd_fonts = cli_options
212+
.visuals
213+
.nerd_fonts
214+
.unwrap_or(config_options.nerd_fonts);
188215

189216
Ok(InfoBuilder::new(cli_options, config_options)
190217
.title(&repo, no_bold, &text_colors)
@@ -199,7 +226,7 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
199226
true_color,
200227
number_of_languages_to_display,
201228
&text_colors,
202-
cli_options,
229+
nerd_fonts,
203230
)
204231
.dependencies(manifest.as_ref(), number_separator)
205232
.authors(
@@ -221,7 +248,13 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
221248
.loc(&loc_by_language, number_separator)
222249
.size(&repo, number_separator)
223250
.license(&repo_path, manifest.as_ref())?
224-
.build(cli_options, text_colors, dominant_language, ascii_colors))
251+
.build(
252+
cli_options,
253+
no_bold,
254+
text_colors,
255+
dominant_language,
256+
ascii_colors,
257+
))
225258
}
226259

227260
impl InfoBuilder {
@@ -336,15 +369,15 @@ impl InfoBuilder {
336369
true_color: bool,
337370
number_of_languages: usize,
338371
text_colors: &TextColors,
339-
cli_options: &CliOptions,
372+
nerd_fonts: bool,
340373
) -> Self {
341374
if !self.disabled_fields.contains(&InfoType::Languages) {
342375
let languages = LanguagesInfo::new(
343376
loc_by_language,
344377
true_color,
345378
number_of_languages,
346379
text_colors.info,
347-
cli_options.visuals.nerd_fonts,
380+
nerd_fonts,
348381
);
349382
self.info_fields.push(Box::new(languages));
350383
}
@@ -456,6 +489,7 @@ impl InfoBuilder {
456489
fn build(
457490
self,
458491
cli_options: &CliOptions,
492+
no_bold: bool,
459493
text_colors: TextColors,
460494
dominant_language: Language,
461495
ascii_colors: Vec<DynColors>,
@@ -467,7 +501,7 @@ impl InfoBuilder {
467501
dominant_language,
468502
ascii_colors,
469503
no_color_palette: cli_options.visuals.no_color_palette,
470-
no_bold: cli_options.text_formatting.no_bold,
504+
no_bold: no_bold,
471505
}
472506
}
473507
}

0 commit comments

Comments
 (0)