Skip to content

Commit c4fdd83

Browse files
committed
interesting
1 parent 9f9f974 commit c4fdd83

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

Cargo.lock

Lines changed: 8 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ members = ["ascii", "image", "manifest"]
1111
[workspace.dependencies]
1212
owo-colors = "4.2.0"
1313
anyhow = "1.0"
14-
clap = { version = "4.5.34", features = ["derive"] }
14+
clap = { version = "4.5.34", features = ["derive","string", ] }
1515
image = { version = "0.25.5", default-features = false, features = [
1616
"color_quant",
1717
"jpeg",

src/cli.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use crate::config::ConfigOptions;
12
use crate::info::langs::language::{Language, LanguageType};
23
use crate::info::utils::info_field::InfoType;
34
use crate::ui::printer::SerializationFormat;
45
use anyhow::Result;
5-
use clap::builder::PossibleValuesParser;
6+
use clap::builder::{OsStr, PossibleValuesParser};
67
use clap::builder::TypedValueParser as _;
78
use clap::{value_parser, Args, Command, Parser, ValueHint};
89
use clap_complete::{generate, Generator, Shell};
@@ -54,7 +55,8 @@ pub struct InfoCliOptions {
5455
num_args = 1..,
5556
hide_possible_values = true,
5657
value_enum,
57-
value_name = "FIELD"
58+
value_name = "FIELD",
59+
default_value = Vec::<String>::new().join(""),
5860
)]
5961
pub disabled_fields: Vec<InfoType>,
6062
/// Hides the title
@@ -219,9 +221,10 @@ pub struct VisualsCliOptions {
219221
#[command(next_help_heading = "CONFIG")]
220222
pub struct ConfigCliOptions {
221223
/// Path to the config file
222-
#[arg(long, value_hint = ValueHint::FilePath)]
223-
pub config_path: Option<PathBuf>,
224+
#[arg(long, value_hint = ValueHint::FilePath, default_value = ConfigCliOptions::default().config_path.into_os_string())]
225+
pub config_path: PathBuf,
224226
/// Creates a default config file
227+
///
225228
/// Writes to $XDG_CONFIG_HOME/onefetch/config.toml but can be overridden with --config-path
226229
#[arg(long)]
227230
pub generate_config: bool,
@@ -321,7 +324,9 @@ impl Default for ConfigCliOptions {
321324
fn default() -> Self {
322325
ConfigCliOptions {
323326
// Not sure about unwrap
324-
config_path: Some(dirs::config_dir().expect("Could not find $HOME!").join("onefetch/config.toml")),
327+
config_path: dirs::config_dir()
328+
.expect("Could not find $HOME!")
329+
.join("onefetch/config.toml"),
325330
generate_config: false,
326331
}
327332
}

src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use human_panic::setup_panic;
66
use onefetch::cli::{self, CliOptions};
77
use onefetch::config::ConfigOptions;
88
use onefetch::info::build_info;
9+
use onefetch::info::utils::info_field::InfoType;
910
use onefetch::ui::printer::Printer;
1011
use std::io;
12+
use std::process::exit;
1113

1214
fn main() -> Result<()> {
1315
setup_panic!();
@@ -32,22 +34,20 @@ fn main() -> Result<()> {
3234
}
3335

3436
if cli_options.config.generate_config {
35-
return ConfigOptions::default().write(
36-
&cli_options.config.config_path.unwrap_or(
37-
dirs::config_dir()
38-
.expect("Could not find config dir!")
39-
.join("onefetch/config.toml"),
40-
),
41-
);
37+
return ConfigOptions::default().write(&cli_options.config.config_path);
4238
}
4339

44-
let config_options = ConfigOptions::read(
45-
&cli_options.config.config_path.as_ref().unwrap_or(
46-
&dirs::config_dir()
47-
.expect("Could not find config dir!")
48-
.join("onefetch/config.toml"),
49-
),
50-
);
40+
let config_options = ConfigOptions::read(&cli_options.config.config_path);
41+
42+
{
43+
let merged_disabled: Vec<InfoType> = config_options
44+
.disabled_fields
45+
.into_iter()
46+
.chain(cli_options.info.disabled_fields)
47+
.collect();
48+
println!("{:?}", merged_disabled);
49+
exit(0)
50+
}
5151

5252
let info = build_info(&cli_options, &config_options)?;
5353

0 commit comments

Comments
 (0)