Skip to content

Commit

Permalink
Add more debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cestef committed Mar 21, 2024
1 parent 4635d11 commit ce58b42
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 26 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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());
Expand All @@ -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::<Opts>();
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 {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit ce58b42

Please sign in to comment.