Skip to content

Commit

Permalink
better handling of windows of foreach command
Browse files Browse the repository at this point in the history
Though it still does not work on Windows, at least it gives a better error message.
  • Loading branch information
jqnatividad committed Oct 11, 2021
1 parent deac0e5 commit e54905f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/cmd/foreach.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(target_family = "unix")]
use crate::regex::bytes::{NoExpand, Regex};
use std::ffi::OsStr;
use std::io::BufReader;
#[cfg(target_family = "unix")]
use std::os::unix::ffi::OsStrExt;
use std::process::{Command, Stdio};

Expand All @@ -12,7 +12,8 @@ use crate::CliResult;
use serde::Deserialize;

static USAGE: &str = "
Execute a bash command once per line in given CSV file.
Execute a bash command once per line in given CSV file. Works only in
Unix-like environments.
Deleting all files whose filenames are listed in a column:
Expand Down Expand Up @@ -64,7 +65,8 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.select(args.arg_column);

if cfg!(windows) {
panic!("foreach command does not work on Windows");
println!("foreach command does not work on Windows");
return Ok(())
}

let mut rdr = rconfig.reader()?;
Expand All @@ -90,7 +92,10 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

let mut command_pieces = splitter_pattern.find_iter(&templated_command);

#[cfg(target_family = "unix")]
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
1 change: 0 additions & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod fill;
pub mod fixlengths;
pub mod flatten;
pub mod fmt;
#[cfg(target_family = "unix")]
pub mod foreach;
pub mod frequency;
pub mod headers;
Expand Down
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern crate reverse_geocoder;
extern crate serde;
extern crate serde_json;
extern crate tabwriter;
//extern crate textwrap;
extern crate threadpool;
extern crate uuid;

Expand Down Expand Up @@ -208,7 +207,7 @@ enum Command {
Stats,
Table,
Transpose,
#[cfg(target_family = "unix")]
// #[cfg(target_family = "unix")]
ForEach,
}

Expand Down Expand Up @@ -263,7 +262,6 @@ impl Command {
Command::Stats => cmd::stats::run(argv),
Command::Table => cmd::table::run(argv),
Command::Transpose => cmd::transpose::run(argv),
#[cfg(target_family = "unix")]
Command::ForEach => cmd::foreach::run(argv),
}
}
Expand Down

0 comments on commit e54905f

Please sign in to comment.