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

feat: tojsonl add --quiet option #2336

Merged
merged 1 commit into from
Dec 5, 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
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
Loading