From 0fffcc663af9b720c20d4e72a7efaa5dc7e7d181 Mon Sep 17 00:00:00 2001 From: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:53:50 +0100 Subject: [PATCH] feat: adds dotfile as default rules file Signed-off-by: ChrisJBurns <29541485+ChrisJBurns@users.noreply.github.com> --- src/main.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3bff5c0..f6dadce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use std::collections::HashSet; -use std::fs; +use std::{env, fs}; use clap::Parser; @@ -12,8 +12,8 @@ pub mod sdkman; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { - /// Filename of the YAML config file - #[arg(short, long)] + /// Filename of the YAML config file. + #[arg(short, long, default_value_t = get_rules_dotfile())] file: String, /// Just print out the commands that would be executed @@ -25,6 +25,17 @@ struct Args { no_uninstall: bool, } +fn get_rules_dotfile() -> String { + format!( + "{}/{}", + match env::var_os("HOME") { + Some(v) => v.into_string().unwrap(), + None => panic!("$HOME environment variable is not set"), + }, + String::from(".sdk-rules.yaml") + ) +} + fn main() { let args = Args::parse();