diff --git a/src/lib.rs b/src/lib.rs index 872cb4d..ae895ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,10 @@ pub async fn _main(opts: Opts) -> Result<()> { saved_opts } else { let err = save.as_ref().unwrap_err(); - error!("Error while parsing save file: {}", err); + error!( + "Error while parsing save file: {}, using passed options", + err.to_string().bold().red() + ); opts.clone() } } else { diff --git a/src/main.rs b/src/main.rs index d0fad0b..d79d6ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ use merge::Merge; use rwalk::{ _main, cli::{self, opts::Opts}, - utils, + utils::{ + self, + constants::{COMPLETIONS_PATH, DEFAULT_CONFIG_PATH}, + }, }; use std::{fs::OpenOptions, path::Path, process}; @@ -18,12 +21,15 @@ async fn main() -> Result<()> { utils::logger::init_logger(); let mut opts = Opts::parse(); + if let Some(p) = opts.config { opts = Opts::from_path(p.clone()).await?; log::debug!("Using config file: {}", p); } else if let Some(home) = dirs::home_dir() { - let p = home.join(Path::new(".config/rwalk/config.toml")); + log::debug!("Home directory found: {}", home.display()); + let p = home.join(Path::new(DEFAULT_CONFIG_PATH)); if p.exists() { + log::debug!("Config file found: {}", p.display()); let path_opts = Opts::from_path(p.clone()).await?; opts.merge(path_opts); log::debug!("Using config file: {}", p.display()); @@ -32,41 +38,51 @@ async fn main() -> Result<()> { log::debug!("No home directory found"); } + log::debug!("Parsed options: {:#?}", opts); + if opts.generate_markdown { clap_markdown::print_help_markdown::(); process::exit(0); } + if opts.generate_completions { + let name = env!("CARGO_PKG_NAME"); + let dir = Path::new(COMPLETIONS_PATH); + if !dir.exists() { + log::debug!("Creating completions directory: {}", dir.display()); + std::fs::create_dir_all(dir)?; + } for s in Shell::value_variants().iter() { - let dir = Path::new("completions"); - if !dir.exists() { - std::fs::create_dir_all(dir)?; - } + log::debug!("Generating completions for {}", s); let mut file = OpenOptions::new() .write(true) .create(true) .truncate(true) - .open(dir.join(s.file_name("rwalk")))?; - generate(*s, &mut Opts::command(), "rwalk", &mut file); + .open(dir.join(s.file_name(name)))?; + generate(*s, &mut Opts::command(), name, &mut file); } + log::debug!("Generating completions for nushell"); // Generate completions for nushell let mut file = OpenOptions::new() .write(true) .create(true) .truncate(true) - .open("completions/rwalk.nu")?; - generate(Nushell, &mut Opts::command(), "rwalk", &mut file); + .open(dir.join(Nushell.file_name(name)))?; + generate(Nushell, &mut Opts::command(), name, &mut file); log::info!("Generated completions"); process::exit(0); } + if opts.no_color { colored::control::set_override(false); } + if !opts.quiet { utils::banner(); } + let res = if opts.interactive { cli::interactive::main().await } else { diff --git a/src/utils/constants.rs b/src/utils/constants.rs index 5acf61b..bbfa779 100644 --- a/src/utils/constants.rs +++ b/src/utils/constants.rs @@ -23,3 +23,5 @@ pub const DEFAULT_METHOD: &str = "GET"; pub const DEFAULT_MODE: &str = "recursive"; pub const DEFAULT_DEPTH: usize = 1; pub const DEFAULT_FILE_TYPE: &str = "txt"; +pub const COMPLETIONS_PATH: &str = "completions"; +pub const DEFAULT_CONFIG_PATH: &str = ".config/rwalk/config.toml";