Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default log level when not using RUST_LOG #206

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use std::{
use anyhow::{anyhow, Context};
use clap::{CommandFactory, Parser};
use clap_complete::Generator;
use flexi_logger::AdaptiveFormat;
use ignore::{overrides::OverrideBuilder, types::TypesBuilder, WalkBuilder};
use log::error;
use log::{error, info};
use rayon::iter::ParallelBridge;
#[cfg(feature = "go")]
use typeshare_core::language::Go;
Expand All @@ -37,13 +38,15 @@ use crate::{
};

fn main() -> anyhow::Result<()> {
flexi_logger::Logger::try_with_env()
.unwrap()
.start()
.unwrap();
flexi_logger::Logger::try_with_env_or_str("info")?
.adaptive_format_for_stderr(AdaptiveFormat::Detailed)
.adaptive_format_for_stdout(AdaptiveFormat::Detailed)
.start()?;

let options = Args::parse();

info!("typeshare started generating types");

if let Some(options) = options.subcommand {
match options {
Command::Completions { shell } => {
Expand Down Expand Up @@ -153,13 +156,15 @@ fn main() -> anyhow::Result<()> {
};

check_parse_errors(&crate_parsed_data)?;

write_generated(
destination,
lang.as_mut(),
crate_parsed_data,
import_candidates,
)?;

info!("typeshare finished generating types");
Ok(())
}

Expand Down Expand Up @@ -262,13 +267,14 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
errors_encountered = true;
for error in &data.errors {
error!(
"Parsing error: \"{}\" in crate \"{}\" for file \"{}\"",
error.error, error.crate_name, error.file_name
"Parsing error: \"{}\" in file \"{}\"",
error.error, error.file_name
);
}
}

if errors_encountered {
error!("Errors encountered during parsing.");
Err(anyhow!("Errors encountered during parsing."))
} else {
Ok(())
Expand Down
2 changes: 0 additions & 2 deletions core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ pub enum ParseError {
/// Error with it's related data.
#[derive(Debug)]
pub struct ErrorInfo {
/// The crate where this error occurred.
pub crate_name: CrateName,
/// The file name being parsed.
pub file_name: String,
/// The parse error.
Expand Down
4 changes: 1 addition & 3 deletions core/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const IGNORED_TYPES: &[&str] = &["Option", "String", "Vec", "HashMap", "T", "I54
#[derive(Default)]
pub struct TypeShareVisitor<'a> {
parsed_data: ParsedData,
#[allow(dead_code)]
file_path: PathBuf,
ignored_types: &'a [&'a str],
target_os: &'a [String],
Expand Down Expand Up @@ -92,8 +91,7 @@ impl<'a> TypeShareVisitor<'a> {
match result {
Ok(data) => self.parsed_data.push(data),
Err(error) => self.parsed_data.errors.push(ErrorInfo {
crate_name: self.parsed_data.crate_name.clone(),
file_name: self.parsed_data.file_name.clone(),
file_name: self.file_path.to_string_lossy().into_owned(),
error,
}),
}
Expand Down
Loading