Skip to content

Commit

Permalink
feat: add template command to qsvdp binary variant
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Jan 12, 2025
1 parent 0e0485b commit 9df85e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub mod sqlp;
pub mod stats;
#[cfg(any(feature = "feature_capable", feature = "lite"))]
pub mod table;
#[cfg(feature = "feature_capable")]
#[cfg(any(feature = "feature_capable", feature = "datapusher_plus"))]
pub mod template;
#[cfg(all(feature = "to", feature = "feature_capable"))]
pub mod to;
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ use std::{
};

use ahash::{HashMap, HashMapExt};
#[cfg(any(feature = "feature_capable", feature = "lite"))]
use indicatif::{ProgressBar, ProgressDrawTarget};
use minijinja::{value::ValueKind, Environment, Value};
use minijinja_contrib::pycompat::unknown_method_callback;
Expand Down Expand Up @@ -162,6 +163,7 @@ struct Args {
flag_batch: usize,
flag_delimiter: Option<Delimiter>,
flag_no_headers: bool,
#[allow(dead_code)]
flag_progressbar: bool,
flag_timeout: u16,
flag_cache_dir: String,
Expand Down Expand Up @@ -342,10 +344,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let batchsize = util::optimal_batch_size(&rconfig, args.flag_batch, num_jobs);

// prep progress bar
#[cfg(any(feature = "feature_capable", feature = "lite"))]
let show_progress =
(args.flag_progressbar || util::get_envvar_flag("QSV_PROGRESSBAR")) && !rconfig.is_stdin();

#[cfg(any(feature = "feature_capable", feature = "lite"))]
let progress = ProgressBar::with_draw_target(None, ProgressDrawTarget::stderr_with_hz(5));
#[cfg(any(feature = "feature_capable", feature = "lite"))]
if show_progress {
util::prep_progress(&progress, rowcount);
} else {
Expand Down Expand Up @@ -567,13 +571,15 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
}
}

#[cfg(any(feature = "feature_capable", feature = "lite"))]
if show_progress {
progress.inc(batch.len() as u64);
}

batch.clear();
} // end batch loop

#[cfg(any(feature = "feature_capable", feature = "lite"))]
if show_progress {
util::finish_progress(&progress);
}
Expand Down
3 changes: 3 additions & 0 deletions src/maindp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static COMMAND_LIST: &str = r#"
sortcheck Check if a CSV is sorted
sqlp Run a SQL query against several CSVs using the Pola.rs engine
stats Infer data types and compute summary statistics
template Render templates using CSV data
validate Validate CSV data for RFC4180-compliance or with JSON Schema
NOTE: qsvdp ignores the --progressbar option for all commands."#;
Expand Down Expand Up @@ -277,6 +278,7 @@ enum Command {
#[cfg(feature = "polars")]
SqlP,
Stats,
Template,
Validate,
}

Expand Down Expand Up @@ -336,6 +338,7 @@ impl Command {
#[cfg(feature = "polars")]
Command::SqlP => cmd::sqlp::run(argv),
Command::Stats => cmd::stats::run(argv),
Command::Template => cmd::template::run(argv),
Command::Validate => cmd::validate::run(argv),
}
}
Expand Down

0 comments on commit 9df85e6

Please sign in to comment.