diff --git a/src/arguments.rs b/src/arguments.rs index 774c2ce..3137034 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -11,4 +11,8 @@ pub struct Arguments { /// the input files to edit #[arg(value_name = "files")] pub files: Vec, + + /// print the path to the config file + #[arg(short, long)] + pub show_config_path: bool, } diff --git a/src/config.rs b/src/config.rs index 0889150..b62f7e2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -34,7 +34,7 @@ pub struct Keypress { impl Config { #[cfg(unix)] - fn path() -> Option { + fn default_path() -> Option { env::var_os("XDG_CONFIG_HOME") .map(PathBuf::from) .take_if(|xdg_config_home| xdg_config_home.is_absolute()) @@ -43,14 +43,17 @@ impl Config { } #[cfg(windows)] - fn path() -> Option { + fn default_path() -> Option { // this isn't technically the right way but it should be good enough home_dir().map(|home| home.join("AppData").join("Roaming")) } + pub fn path(override_path: Option) -> Option { + override_path.or_else(Self::default_path) + } + pub fn init(override_path: Option) -> Result { - let path = override_path - .or_else(Self::path) + let path = Self::path(override_path) .ok_or(ConfigInitError::NoConfigPath)?; let raw_config = read_to_string(path)?; diff --git a/src/main.rs b/src/main.rs index b88811d..139246e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,8 @@ use clap::Parser; use app::App; use crossterm::{QueueableCommand, event::{DisableMouseCapture, EnableMouseCapture}}; +use crate::config::Config; + mod app; mod buffer; mod popup; @@ -33,12 +35,12 @@ const LINES_OF_PADDING: usize = 5; const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // TODO: -// - update showcase // - write docs // - simonomi.dev/hexapoda? // - config // - schema!! // - uhhhhh? +// - update showcase // - fix scroll clamping // - inspector translations for varint // - search @@ -71,6 +73,20 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; fn main() { let arguments = Arguments::parse(); + if arguments.show_config_path { + if let Some(path) = Config::path(arguments.config) { + println!("{}", path.display()); + } else { + #[cfg(unix)] { + println!("currently, no config file will be used. define the environment variable XDG_CONFIG_HOME or use the -c/--config option to provide one"); + } + #[cfg(windows)] { + println!("currently, no config file will be used. use the -c/--config option to provide one"); + } + } + return; + } + let mut app = App::new( arguments.config, &arguments.files