Skip to content

Commit

Permalink
foeach: cleanup
Browse files Browse the repository at this point in the history
- fine-tune conditional compilation logic so we don't really compile it for windows
- make sure workdir name says foreach
  • Loading branch information
jqnatividad committed Apr 9, 2022
1 parent e050cf5 commit a37effd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
14 changes: 2 additions & 12 deletions src/cmd/foreach.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg(target_family = "unix")]
use regex::bytes::{NoExpand, Regex};
#[allow(unused_imports)]
use std::ffi::OsStr;
use std::io::BufReader;
#[cfg(target_family = "unix")]
use std::os::unix::ffi::OsStrExt;
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -68,10 +67,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.no_headers(args.flag_no_headers)
.select(args.arg_column);

if cfg!(windows) {
return fail!("foreach command does not work on Windows.");
}

let mut rdr = rconfig.reader()?;
let mut wtr = Config::new(&None).writer()?;

Expand Down Expand Up @@ -105,13 +100,8 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.replace_all(args.arg_command.as_bytes(), current_value)
.to_vec();

#[allow(unused_mut)]
let mut command_pieces = splitter_pattern.find_iter(&templated_command);

#[cfg(target_family = "unix")]
let command_pieces = splitter_pattern.find_iter(&templated_command);
let prog = OsStr::from_bytes(command_pieces.next().unwrap().as_bytes());
#[cfg(target_family = "windows")]
let prog = "dummy var so it compiles on Windows";

let cmd_args: Vec<String> = command_pieces
.map(|piece| {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod fill;
pub mod fixlengths;
pub mod flatten;
pub mod fmt;
#[cfg(all(feature = "foreach", not(feature = "lite")))]
#[cfg(all(feature = "foreach", target_family = "unix", not(feature = "lite")))]
pub mod foreach;
pub mod frequency;
#[cfg(all(feature = "generate", not(feature = "lite")))]
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ enum Command {
FixLengths,
Flatten,
Fmt,
#[cfg(all(feature = "foreach", not(feature = "lite")))]
#[cfg(all(feature = "foreach", target_family = "unix", not(feature = "lite")))]
ForEach,
Frequency,
#[cfg(all(feature = "generate", not(feature = "lite")))]
Expand Down Expand Up @@ -293,6 +293,8 @@ impl Command {
Command::Explode => cmd::explode::run(argv),
#[cfg(all(feature = "fetch", not(feature = "lite")))]
Command::Fetch => cmd::fetch::run(argv),
#[cfg(all(feature = "foreach", target_family = "unix", not(feature = "lite")))]
Command::ForEach => cmd::foreach::run(argv),
Command::Fill => cmd::fill::run(argv),
Command::FixLengths => cmd::fixlengths::run(argv),
Command::Flatten => cmd::flatten::run(argv),
Expand Down Expand Up @@ -332,8 +334,6 @@ impl Command {
Command::Table => cmd::table::run(argv),
Command::Transpose => cmd::transpose::run(argv),
Command::Validate => cmd::validate::run(argv),
#[cfg(all(feature = "foreach", not(feature = "lite")))]
Command::ForEach => cmd::foreach::run(argv),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_foreach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::workdir::Workdir;

#[test]
fn foreach() {
let wrk = Workdir::new("apply");
let wrk = Workdir::new("foreach");
wrk.create(
"data.csv",
vec![svec!["name"], svec!["John"], svec!["Mary"]],
Expand All @@ -18,7 +18,7 @@ fn foreach() {

#[test]
fn foreach_unify() {
let wrk = Workdir::new("apply");
let wrk = Workdir::new("foreach_unify");
wrk.create(
"data.csv",
vec![svec!["name"], svec!["John"], svec!["Mary"]],
Expand All @@ -40,7 +40,7 @@ fn foreach_unify() {

#[test]
fn foreach_new_column() {
let wrk = Workdir::new("apply");
let wrk = Workdir::new("foreach_nc");
wrk.create(
"data.csv",
vec![svec!["name"], svec!["John"], svec!["Mary"]],
Expand Down

0 comments on commit a37effd

Please sign in to comment.