Skip to content

Commit 806e3cd

Browse files
committed
cli: config file related flags
1 parent 0ed9c9d commit 806e3cd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/cli.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct CliOptions {
3737
#[command(flatten)]
3838
pub visuals: VisualsCliOptions,
3939
#[command(flatten)]
40+
pub config: ConfigCliOptions,
41+
#[command(flatten)]
4042
pub developer: DeveloperCliOptions,
4143
#[command(flatten)]
4244
pub other: OtherCliOptions,
@@ -213,6 +215,18 @@ pub struct VisualsCliOptions {
213215
pub nerd_fonts: bool,
214216
}
215217

218+
#[derive(Clone, Debug, Args, PartialEq, Eq)]
219+
#[command(next_help_heading = "CONFIG")]
220+
pub struct ConfigCliOptions {
221+
/// Path to the config file
222+
#[arg(long, value_hint = ValueHint::FilePath)]
223+
pub config_path: Option<PathBuf>,
224+
/// Creates a default config file
225+
/// Writes to $XDG_CONFIG_HOME/onefetch/config.toml but can be overridden with --config-path
226+
#[arg(long)]
227+
pub generate_config: bool,
228+
}
229+
216230
#[derive(Clone, Debug, Args, PartialEq, Eq, Default)]
217231
#[command(next_help_heading = "DEVELOPER")]
218232
pub struct DeveloperCliOptions {
@@ -244,6 +258,7 @@ impl Default for CliOptions {
244258
visuals: VisualsCliOptions::default(),
245259
ascii: AsciiCliOptions::default(),
246260
image: ImageCliOptions::default(),
261+
config: ConfigCliOptions::default(),
247262
developer: DeveloperCliOptions::default(),
248263
other: OtherCliOptions::default(),
249264
}
@@ -302,6 +317,20 @@ impl Default for ImageCliOptions {
302317
}
303318
}
304319

320+
impl Default for ConfigCliOptions {
321+
fn default() -> Self {
322+
ConfigCliOptions {
323+
// Not sure about unwrap
324+
config_path: Some(
325+
dirs::config_dir()
326+
.expect("Could not find $HOME!")
327+
.join("onefetch/config.toml"),
328+
),
329+
generate_config: false,
330+
}
331+
}
332+
}
333+
305334
pub fn print_supported_languages() -> Result<()> {
306335
for l in Language::iter() {
307336
println!("{l}");

0 commit comments

Comments
 (0)