From e4c6336bd41f785f6b9a2200fb58f32796eb4380 Mon Sep 17 00:00:00 2001 From: Chris Gillespie <6572184+gillespiecd@users.noreply.github.com> Date: Wed, 30 Sep 2020 22:22:19 -0700 Subject: [PATCH] Convert to string before clip (#2624) --- crates/nu-cli/src/commands/clip.rs | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/nu-cli/src/commands/clip.rs b/crates/nu-cli/src/commands/clip.rs index 86eed7daf7..4f62c597af 100644 --- a/crates/nu-cli/src/commands/clip.rs +++ b/crates/nu-cli/src/commands/clip.rs @@ -32,11 +32,18 @@ impl WholeStreamCommand for Clip { } fn examples(&self) -> Vec { - vec![Example { - description: "Save text to the clipboard", - example: "echo 'secret value' | clip", - result: None, - }] + 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(_) => { - return Err(ShellError::labeled_error( - "Given non-string data", - "expected strings from pipeline", - name, - )) - } - }; + let string: String = i.convert_to_string(); + if string.is_empty() { + return Err(ShellError::labeled_error( + "Unable to convert to string", + "Unable to convert to string", + name, + )); + } new_copy_data.push_str(&string); }