Attempt so simplify classified

This commit is contained in:
Jonathan Turner 2019-09-08 14:00:04 +12:00
parent 84628f298d
commit 9da896ad4e
3 changed files with 52 additions and 118 deletions

View file

@ -220,9 +220,7 @@ impl ExternalCommand {
let mut process;
#[cfg(windows)]
{
process = Exec::shell(&self.name);
process = Exec::cmd(&self.name);
if arg_string.contains("$it") {
let mut first = true;
@ -275,56 +273,7 @@ impl ExternalCommand {
}
}
}
}
#[cfg(not(windows))]
{
let mut new_arg_string = self.name.to_string();
if arg_string.contains("$it") {
let mut first = true;
for i in &inputs {
let i = match i.as_string() {
Err(_err) => {
let mut span = name_span;
for arg in &self.args {
if arg.item.contains("$it") {
span = arg.span();
}
}
return Err(ShellError::labeled_error(
"External $it needs string data",
"given row instead of string data",
span,
));
}
Ok(val) => val,
};
if !first {
new_arg_string.push_str("&&");
new_arg_string.push_str(&self.name);
} else {
first = false;
}
for arg in &self.args {
if arg.chars().all(|c| c.is_whitespace()) {
continue;
}
new_arg_string.push_str(" ");
new_arg_string.push_str(&arg.replace("$it", &i));
}
}
} else {
for arg in &self.args {
new_arg_string.push_str(" ");
new_arg_string.push_str(&arg);
}
}
process = Exec::shell(new_arg_string);
}
process = process.cwd(context.shell_manager.path());
let mut process = match stream_next {

View file

@ -310,8 +310,7 @@ pub fn file_contents(full_path: impl AsRef<Path>) -> String {
pub fn file_contents_binary(full_path: impl AsRef<Path>) -> Vec<u8> {
let mut file = std::fs::File::open(full_path.as_ref()).expect("can not open file");
let mut contents = Vec::new();
file.read_to_end(&mut contents)
.expect("can not read file");
file.read_to_end(&mut contents).expect("can not read file");
contents
}
@ -327,18 +326,6 @@ pub fn line_ending() -> String {
}
}
pub fn normalize_string(input: &str) -> String {
#[cfg(windows)]
{
input.to_string()
}
#[cfg(not(windows))]
{
format!("\"{}\"", input)
}
}
pub fn create_file_at(full_path: impl AsRef<Path>) -> Result<(), std::io::Error> {
let full_path = full_path.as_ref();
@ -377,9 +364,9 @@ pub fn in_directory(str: impl AsRef<Path>) -> String {
str.as_ref().display().to_string()
}
pub fn pipeline(commands: &str) -> String {
commands.lines()
commands
.lines()
.skip(1)
.map(|line| line.trim())
.collect::<Vec<&str>>()

View file

@ -38,9 +38,7 @@ fn external_has_correct_quotes() {
r#"echo "hello world""#
);
let actual = h::normalize_string(&actual);
assert_eq!(actual, r#""hello world""#);
assert_eq!(actual, r#"hello world"#);
}
#[test]