diff --git a/cli/src/main.rs b/cli/src/main.rs index 3a108c48..59589dc4 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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; @@ -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 } => { @@ -153,6 +156,7 @@ fn main() -> anyhow::Result<()> { }; check_parse_errors(&crate_parsed_data)?; + write_generated( destination, lang.as_mut(), @@ -160,6 +164,7 @@ fn main() -> anyhow::Result<()> { import_candidates, )?; + info!("typeshare finished generating types"); Ok(()) } @@ -262,13 +267,14 @@ fn check_parse_errors(parsed_crates: &BTreeMap) -> 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(()) diff --git a/core/src/parser.rs b/core/src/parser.rs index c6dac11f..3f2f2159 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -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. diff --git a/core/src/visitors.rs b/core/src/visitors.rs index 8a566060..8ac113e4 100644 --- a/core/src/visitors.rs +++ b/core/src/visitors.rs @@ -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], @@ -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, }), }