Skip to content

Commit dce5b85

Browse files
Set default log level when not using RUST_LOG (1Password#206)
* set default log level when not using RUST_LOG * update error output for parsing failures * Use adaptive format for coloring when possible * remove dead_code attribute
1 parent 330a40f commit dce5b85

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

cli/src/main.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use std::{
1616
use anyhow::{anyhow, Context};
1717
use clap::{CommandFactory, Parser};
1818
use clap_complete::Generator;
19+
use flexi_logger::AdaptiveFormat;
1920
use ignore::{overrides::OverrideBuilder, types::TypesBuilder, WalkBuilder};
20-
use log::error;
21+
use log::{error, info};
2122
use rayon::iter::ParallelBridge;
2223
#[cfg(feature = "go")]
2324
use typeshare_core::language::Go;
@@ -37,13 +38,15 @@ use crate::{
3738
};
3839

3940
fn main() -> anyhow::Result<()> {
40-
flexi_logger::Logger::try_with_env()
41-
.unwrap()
42-
.start()
43-
.unwrap();
41+
flexi_logger::Logger::try_with_env_or_str("info")?
42+
.adaptive_format_for_stderr(AdaptiveFormat::Detailed)
43+
.adaptive_format_for_stdout(AdaptiveFormat::Detailed)
44+
.start()?;
4445

4546
let options = Args::parse();
4647

48+
info!("typeshare started generating types");
49+
4750
if let Some(options) = options.subcommand {
4851
match options {
4952
Command::Completions { shell } => {
@@ -153,13 +156,15 @@ fn main() -> anyhow::Result<()> {
153156
};
154157

155158
check_parse_errors(&crate_parsed_data)?;
159+
156160
write_generated(
157161
destination,
158162
lang.as_mut(),
159163
crate_parsed_data,
160164
import_candidates,
161165
)?;
162166

167+
info!("typeshare finished generating types");
163168
Ok(())
164169
}
165170

@@ -262,13 +267,14 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
262267
errors_encountered = true;
263268
for error in &data.errors {
264269
error!(
265-
"Parsing error: \"{}\" in crate \"{}\" for file \"{}\"",
266-
error.error, error.crate_name, error.file_name
270+
"Parsing error: \"{}\" in file \"{}\"",
271+
error.error, error.file_name
267272
);
268273
}
269274
}
270275

271276
if errors_encountered {
277+
error!("Errors encountered during parsing.");
272278
Err(anyhow!("Errors encountered during parsing."))
273279
} else {
274280
Ok(())

core/src/parser.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ pub enum ParseError {
8080
/// Error with it's related data.
8181
#[derive(Debug)]
8282
pub struct ErrorInfo {
83-
/// The crate where this error occurred.
84-
pub crate_name: CrateName,
8583
/// The file name being parsed.
8684
pub file_name: String,
8785
/// The parse error.

core/src/visitors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const IGNORED_TYPES: &[&str] = &["Option", "String", "Vec", "HashMap", "T", "I54
4949
#[derive(Default)]
5050
pub struct TypeShareVisitor<'a> {
5151
parsed_data: ParsedData,
52-
#[allow(dead_code)]
5352
file_path: PathBuf,
5453
ignored_types: &'a [&'a str],
5554
target_os: &'a [String],
@@ -92,8 +91,7 @@ impl<'a> TypeShareVisitor<'a> {
9291
match result {
9392
Ok(data) => self.parsed_data.push(data),
9493
Err(error) => self.parsed_data.errors.push(ErrorInfo {
95-
crate_name: self.parsed_data.crate_name.clone(),
96-
file_name: self.parsed_data.file_name.clone(),
94+
file_name: self.file_path.to_string_lossy().into_owned(),
9795
error,
9896
}),
9997
}

0 commit comments

Comments
 (0)