Skip to content

Commit

Permalink
refactor: template early return on empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Dec 13, 2024
1 parent 7d17879 commit 9e0a4ad
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cmd/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.no_headers(args.flag_no_headers);
let mut rdr = rconfig.reader()?;

// Get width of rowcount for padding leading zeroes and early return
let rowcount = util::count_rows(&rconfig)?;
if rconfig.no_headers && rowcount == 1 {
return Ok(());
}
let width = rowcount.to_string().len();

// read headers
let headers = if args.flag_no_headers {
csv::StringRecord::new()
Expand Down Expand Up @@ -288,10 +295,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
filename_env.template_from_str("")?
};

// Get width of rowcount for padding leading zeroes
let rowcount = util::count_rows(&rconfig)?;
let width = rowcount.to_string().len();

let mut bulk_wtr = if output_to_dir {
fs::create_dir_all(args.arg_outdir.as_ref().unwrap())?;
None
Expand Down

0 comments on commit 9e0a4ad

Please sign in to comment.