Skip to content

Commit

Permalink
Use proper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Oct 30, 2024
1 parent 9e51a14 commit 45a4f95
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 9 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ edition = "2021"

[dependencies]
clap = { version = "4.5.20", features = ["derive"] }
crossterm = { version = "0.28.1" } # Maybe this gives Windows issues like espflash?
crossterm = "0.28.1"
env_logger = "0.11.5"
esp-metadata = { version = "0.4.0", features = ["clap"] }
log = "0.4.22"
ratatui = { version = "0.29.0", features = ["crossterm"] }
rhai = "1.19.0"

Expand Down
22 changes: 14 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
};

use clap::Parser;
use env_logger::{Builder, Env};
use esp_metadata::Chip;

mod template_files;
Expand Down Expand Up @@ -178,6 +179,10 @@ struct Args {
}

fn main() {
Builder::from_env(Env::default().default_filter_or(log::LevelFilter::Info.as_str()))
.format_target(false)
.init();

let args = Args::parse();

let path = &args
Expand All @@ -186,12 +191,12 @@ fn main() {
.unwrap_or_else(|| env::current_dir().unwrap());

if !path.is_dir() {
eprintln!("Output path must be a directory");
log::error!("Output path must be a directory");
process::exit(-1);
}

if path.join(&args.name).exists() {
eprintln!("Directory already exists");
log::error!("Directory already exists");
process::exit(-1);
}

Expand Down Expand Up @@ -271,7 +276,7 @@ fn main() {
.output()
.unwrap();
} else {
eprintln!("Current directory is already in a git repository, skipping git initialization");
log::warn!("Current directory is already in a git repository, skipping git initialization");
}
}

Expand Down Expand Up @@ -336,7 +341,7 @@ fn process_file(

// that's a bad workaround
if trimmed == "#[rustfmt::skip]" {
println!("Skipping rustfmt");
log::info!("Skipping rustfmt");
continue;
}

Expand Down Expand Up @@ -404,17 +409,18 @@ fn process_options(args: &Args) {
if !option_item.chips().iter().any(|chip| chip == &args.chip)
&& !option_item.chips().is_empty()
{
eprintln!(
"Error: Option '{}' is not supported for chip {}",
option, args.chip
log::error!(
"Option '{}' is not supported for chip {}",
option,
args.chip
);
process::exit(-1);
}
}
}

if args.option.contains(&String::from("ble")) && args.option.contains(&String::from("wifi")) {
eprintln!("Error: Options 'ble' and 'wifi' are mutually exclusive");
log::error!("Options 'ble' and 'wifi' are mutually exclusive");
process::exit(-1);
}
}
Expand Down

0 comments on commit 45a4f95

Please sign in to comment.