Skip to content

Commit 81a9131

Browse files
committed
almost last
1 parent 5e57cdc commit 81a9131

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

src/cli.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use num_format::CustomFormat;
1010
use onefetch_image::ImageProtocol;
1111
use onefetch_manifest::ManifestType;
1212
use regex::Regex;
13-
use serde::Serialize;
13+
use serde::{Deserialize, Serialize};
1414
use std::env;
1515
use std::io;
1616
use std::path::PathBuf;
@@ -59,13 +59,13 @@ pub struct InfoCliOptions {
5959
pub disabled_fields: Option<Vec<InfoType>>,
6060
/// Hides the title
6161
#[arg(long)]
62-
pub no_title: bool,
62+
pub no_title: Option<bool>,
6363
/// Maximum NUM of authors to be shown
64-
#[arg(long, default_value_t = 3usize, value_name = "NUM")]
65-
pub number_of_authors: usize,
64+
#[arg(long, value_name = "NUM")]
65+
pub number_of_authors: Option<usize>,
6666
/// Maximum NUM of languages to be shown
67-
#[arg(long, default_value_t = 6usize, value_name = "NUM")]
68-
pub number_of_languages: usize,
67+
#[arg(long, value_name = "NUM")]
68+
pub number_of_languages: Option<usize>,
6969
/// Maximum NUM of file churns to be shown
7070
#[arg(long, default_value_t = 3usize, value_name = "NUM")]
7171
pub number_of_file_churns: usize,
@@ -268,8 +268,8 @@ impl Default for CliOptions {
268268
impl Default for InfoCliOptions {
269269
fn default() -> Self {
270270
InfoCliOptions {
271-
number_of_authors: 3,
272-
number_of_languages: 6,
271+
number_of_authors: Some(3),
272+
number_of_languages: Some(6),
273273
number_of_file_churns: 3,
274274
churn_pool_size: Option::default(),
275275
exclude: Vec::default(),
@@ -366,15 +366,17 @@ pub fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
366366
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
367367
}
368368

369-
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)]
369+
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Default)]
370370
pub enum When {
371+
#[default]
371372
Auto,
372373
Never,
373374
Always,
374375
}
375376

376-
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug, Serialize, Copy)]
377+
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug, Deserialize, Serialize, Copy, Default)]
377378
pub enum NumberSeparator {
379+
#[default]
378380
Plain,
379381
Comma,
380382
Space,

src/config.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,57 @@ use anyhow::Result;
22
use serde::{Deserialize, Serialize};
33
use std::{fs, path::Path};
44

5-
use crate::info::utils::info_field::InfoType;
5+
use crate::{
6+
cli::{NumberSeparator, When},
7+
info::utils::info_field::InfoType,
8+
};
69

710
#[derive(Serialize, Deserialize)]
811
pub struct ConfigOptions {
12+
// THIS IS JUST A RAW, REALLY WIP CONFIG STRUCTURE
913
#[serde(default)]
1014
pub disabled_fields: Vec<InfoType>,
15+
// Lol is this really will turn into comment?
16+
/// Or maybe this?
17+
#[serde(default)]
18+
pub no_title: bool,
19+
#[serde(default)]
20+
pub number_of_authors: usize,
21+
#[serde(default)]
22+
pub number_of_languages: usize,
23+
#[serde(default)]
24+
pub churn_pool_size: usize,
25+
#[serde(default)]
26+
pub no_merges: bool,
27+
#[serde(default)]
28+
pub include_hidden: bool,
29+
#[serde(default)]
30+
pub iso_time: bool,
31+
#[serde(default)]
32+
pub number_separator: NumberSeparator,
33+
#[serde(default)]
34+
pub no_bold: bool,
35+
#[serde(default)]
36+
pub true_color: When,
37+
#[serde(default)]
38+
pub nerd_fonts: bool,
1139
}
1240

1341
impl Default for ConfigOptions {
1442
fn default() -> Self {
1543
Self {
1644
disabled_fields: vec![],
45+
no_title: false,
46+
number_of_authors: 3usize,
47+
number_of_languages: 6usize,
48+
churn_pool_size: 3usize,
49+
no_merges: false,
50+
include_hidden: false,
51+
iso_time: false,
52+
number_separator: NumberSeparator::Plain,
53+
no_bold: false,
54+
true_color: When::Auto,
55+
nerd_fonts: false,
1756
}
1857
}
1958
}

src/info/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,15 @@ pub fn build_info(cli_options: &CliOptions, config_options: &ConfigOptions) -> R
173173
let no_bold = cli_options.text_formatting.no_bold;
174174
let number_separator = cli_options.text_formatting.number_separator;
175175
let iso_time = cli_options.text_formatting.iso_time;
176-
let number_of_languages_to_display = cli_options.info.number_of_languages;
177-
let number_of_authors_to_display = cli_options.info.number_of_authors;
176+
let number_of_languages_to_display = cli_options
177+
.info
178+
.number_of_languages
179+
.unwrap_or(config_options.number_of_languages);
180+
// This looks weird i think i should refactor unwrapping
181+
let number_of_authors_to_display = cli_options
182+
.info
183+
.number_of_authors
184+
.unwrap_or(config_options.number_of_authors);
178185
let number_of_file_churns_to_display = cli_options.info.number_of_file_churns;
179186
let globs_to_exclude = &cli_options.info.exclude;
180187
let show_email = cli_options.info.email;
@@ -227,7 +234,7 @@ impl InfoBuilder {
227234
.disabled_fields
228235
.clone()
229236
.unwrap_or(config_options.disabled_fields.clone()),
230-
no_title: cli_options.info.no_title,
237+
no_title: cli_options.info.no_title.unwrap_or(config_options.no_title),
231238
}
232239
}
233240

src/info/utils/info_field.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub enum InfoType {
7575
LinesOfCode,
7676
Size,
7777
License,
78+
None,
7879
}
7980

8081
#[cfg(test)]

0 commit comments

Comments
 (0)