Convert to string before clip (#2624)

This commit is contained in:
Chris Gillespie 2020-09-30 22:22:19 -07:00 committed by GitHub
parent 66061192f8
commit e4c6336bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,11 +32,18 @@ impl WholeStreamCommand for Clip {
}
fn examples(&self) -> Vec<Example> {
vec![Example {
vec![
Example {
description: "Save text to the clipboard",
example: "echo 'secret value' | clip",
result: None,
}]
},
Example {
description: "Save numbers to the clipboard",
example: "random integer 10000000..99999999 | clip",
result: None,
},
]
}
}
@ -61,16 +68,14 @@ pub async fn clip(
first = false;
}
let string: String = match i.as_string() {
Ok(string) => string.to_string(),
Err(_) => {
let string: String = i.convert_to_string();
if string.is_empty() {
return Err(ShellError::labeled_error(
"Given non-string data",
"expected strings from pipeline",
"Unable to convert to string",
"Unable to convert to string",
name,
))
));
}
};
new_copy_data.push_str(&string);
}