diff --git a/src/main.rs b/src/main.rs index 6bd877e..70008f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ connect to. On a server that already has a client connected to it you can use `fwd browse ` to open `` in the default browser of the client. -On a server that already has a client connected to it you can use `fwd clip -` +On a server that already has a client connected to it you can use `fwd clip` to read stdin and send it to the clipboard of the client, or `fwd clip ` to send the the contents of `file`. @@ -36,7 +36,7 @@ enum Args { Server, Client(String, bool), Browse(String), - Clip(String), + Clip(Option), Error, } @@ -77,9 +77,9 @@ fn parse_args(args: Vec) -> Args { } } else if rest[0] == "clip" { if rest.len() == 1 { - Args::Client(rest[0].to_string(), sudo.unwrap_or(false)) + Args::Clip(None) } else if rest.len() == 2 { - Args::Clip(rest[1].to_string()) + Args::Clip(Some(rest[1].to_string())) } else { Args::Error } @@ -98,8 +98,8 @@ async fn browse_url(url: &str) { } } -async fn clip_file(file: String) { - if let Err(e) = fwd::clip_file(&file).await { +async fn clip_file(file: Option) { + if let Err(e) = fwd::clip_file(file.as_deref()).await { eprintln!("Unable to copy to the clipboard"); eprintln!("{}", e); std::process::exit(1); @@ -177,11 +177,9 @@ mod tests { assert_arg_parse!(&["foo.com"], Args::Client(_, false)); assert_arg_parse!(&["a"], Args::Client(_, false)); assert_arg_parse!(&["browse"], Args::Client(_, false)); - assert_arg_parse!(&["clip"], Args::Client(_, false)); assert_arg_parse!(&["foo.com", "--sudo"], Args::Client(_, true)); assert_arg_parse!(&["a", "-s"], Args::Client(_, true)); assert_arg_parse!(&["-s", "browse"], Args::Client(_, true)); - assert_arg_parse!(&["-s", "clip"], Args::Client(_, true)); } #[test] @@ -191,8 +189,7 @@ mod tests { #[test] fn clip() { - assert_arg_parse!(&["clip", "garbage"], Args::Clip(_)); - assert_arg_parse!(&["clip", "-"], Args::Clip(_)); + assert_arg_parse!(&["clip"], Args::Clip(None)); } #[test] diff --git a/src/reverse.rs b/src/reverse.rs index 76a89d4..8e0b8ed 100644 --- a/src/reverse.rs +++ b/src/reverse.rs @@ -59,13 +59,17 @@ async fn clip_reader(reader: &mut T) -> Result<()> { } #[inline] -pub async fn clip_file(file: &str) -> Result<()> { - if file == "-" { - let mut stdin = tokio::io::stdin(); - clip_reader(&mut stdin).await?; - } else { - let mut file = tokio::fs::File::open(file).await?; - clip_reader(&mut file).await?; +pub async fn clip_file(file: Option<&str>) -> Result<()> { + // send_reverse_message(Message::Browse(url.to_string())).await + match file { + Some(path) => { + let mut file = tokio::fs::File::open(path).await?; + clip_reader(&mut file).await?; + } + None => { + let mut stdin = tokio::io::stdin(); + clip_reader(&mut stdin).await?; + } } Ok(())