Skip to content

Commit

Permalink
feat: tojsonl add --quiet option
Browse files Browse the repository at this point in the history
resolves #2335
  • Loading branch information
jqnatividad committed Dec 5, 2024
1 parent 0bd9d59 commit a326ad1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/cmd/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

// build schema for each field by their inferred type, min/max value/length, and unique values
let mut properties_map: Map<String, Value> =
match infer_schema_from_stats(&args, &input_filename) {
match infer_schema_from_stats(&args, &input_filename, false) {
Ok(map) => map,
Err(e) => {
return fail_clierror!(
Expand Down Expand Up @@ -209,6 +209,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
pub fn infer_schema_from_stats(
args: &util::SchemaArgs,
input_filename: &str,
quiet: bool,
) -> CliResult<Map<String, Value>> {
// invoke cmd::stats
let (csv_fields, csv_stats) = util::get_stats_records(args, StatsMode::Schema)?;
Expand Down Expand Up @@ -404,14 +405,18 @@ pub fn infer_schema_from_stats(
if enum_list.is_empty() {
if const_value != Value::Null {
field_map.insert("const".to_string(), const_value.clone());
winfo!("Const generated for field '{header_string}': {const_value:?}");
if !quiet {
winfo!("Const generated for field '{header_string}': {const_value:?}");
}
}
} else {
field_map.insert("enum".to_string(), Value::Array(enum_list.clone()));
winfo!(
"Enum list generated for field '{header_string}' ({} value/s)",
enum_list.len()
);
if !quiet {
winfo!(
"Enum list generated for field '{header_string}' ({} value/s)",
enum_list.len()
);
}
}

// add current field definition to properties map
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/tojsonl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Common options:
-o, --output <file> Write output to <file> instead of stdout.
--memcheck Check if there is enough memory to load the entire
CSV into memory using CONSERVATIVE heuristics.
-Q, --quiet Do not display enum/const list inferencing messages.
"#;

use std::{fmt::Write, path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -69,6 +70,7 @@ struct Args {
flag_delimiter: Option<Delimiter>,
flag_output: Option<String>,
flag_memcheck: bool,
flag_quiet: bool,
}

impl From<std::fmt::Error> for CliError {
Expand Down Expand Up @@ -144,7 +146,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
};
// build schema for each field by their inferred type, min/max value/length, and unique values
let properties_map: Map<String, Value> =
match infer_schema_from_stats(&schema_args, &input_filename) {
match infer_schema_from_stats(&schema_args, &input_filename, args.flag_quiet) {
Ok(map) => map,
Err(e) => {
return fail_clierror!("Failed to infer field types: {e}");
Expand Down

0 comments on commit a326ad1

Please sign in to comment.