Compare commits

..

No commits in common. "3b1847d8820d73c1f80defadbbcd5acc2a999c48" and "604f31d8e68f9c6ee3f9a286d0cf7e9074cd4f22" have entirely different histories.

2 changed files with 18 additions and 17 deletions

View file

@ -14,7 +14,7 @@ connect to.
On a server that already has a client connected to it you can use `fwd browse On a server that already has a client connected to it you can use `fwd browse
<url>` to open `<url>` in the default browser of the client. <url>` to open `<url>` 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 <file>` to read stdin and send it to the clipboard of the client, or `fwd clip <file>`
to send the the contents of `file`. to send the the contents of `file`.
@ -36,7 +36,7 @@ enum Args {
Server, Server,
Client(String, bool), Client(String, bool),
Browse(String), Browse(String),
Clip(String), Clip(Option<String>),
Error, Error,
} }
@ -77,9 +77,9 @@ fn parse_args(args: Vec<String>) -> Args {
} }
} else if rest[0] == "clip" { } else if rest[0] == "clip" {
if rest.len() == 1 { if rest.len() == 1 {
Args::Client(rest[0].to_string(), sudo.unwrap_or(false)) Args::Clip(None)
} else if rest.len() == 2 { } else if rest.len() == 2 {
Args::Clip(rest[1].to_string()) Args::Clip(Some(rest[1].to_string()))
} else { } else {
Args::Error Args::Error
} }
@ -98,8 +98,8 @@ async fn browse_url(url: &str) {
} }
} }
async fn clip_file(file: String) { async fn clip_file(file: Option<String>) {
if let Err(e) = fwd::clip_file(&file).await { if let Err(e) = fwd::clip_file(file.as_deref()).await {
eprintln!("Unable to copy to the clipboard"); eprintln!("Unable to copy to the clipboard");
eprintln!("{}", e); eprintln!("{}", e);
std::process::exit(1); std::process::exit(1);
@ -177,11 +177,9 @@ mod tests {
assert_arg_parse!(&["foo.com"], Args::Client(_, false)); assert_arg_parse!(&["foo.com"], Args::Client(_, false));
assert_arg_parse!(&["a"], Args::Client(_, false)); assert_arg_parse!(&["a"], Args::Client(_, false));
assert_arg_parse!(&["browse"], 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!(&["foo.com", "--sudo"], Args::Client(_, true));
assert_arg_parse!(&["a", "-s"], Args::Client(_, true)); assert_arg_parse!(&["a", "-s"], Args::Client(_, true));
assert_arg_parse!(&["-s", "browse"], Args::Client(_, true)); assert_arg_parse!(&["-s", "browse"], Args::Client(_, true));
assert_arg_parse!(&["-s", "clip"], Args::Client(_, true));
} }
#[test] #[test]
@ -191,8 +189,7 @@ mod tests {
#[test] #[test]
fn clip() { fn clip() {
assert_arg_parse!(&["clip", "garbage"], Args::Clip(_)); assert_arg_parse!(&["clip"], Args::Clip(None));
assert_arg_parse!(&["clip", "-"], Args::Clip(_));
} }
#[test] #[test]

View file

@ -59,13 +59,17 @@ async fn clip_reader<T: AsyncRead + Unpin>(reader: &mut T) -> Result<()> {
} }
#[inline] #[inline]
pub async fn clip_file(file: &str) -> Result<()> { pub async fn clip_file(file: Option<&str>) -> Result<()> {
if file == "-" { // send_reverse_message(Message::Browse(url.to_string())).await
let mut stdin = tokio::io::stdin(); match file {
clip_reader(&mut stdin).await?; Some(path) => {
} else { let mut file = tokio::fs::File::open(path).await?;
let mut file = tokio::fs::File::open(file).await?; clip_reader(&mut file).await?;
clip_reader(&mut file).await?; }
None => {
let mut stdin = tokio::io::stdin();
clip_reader(&mut stdin).await?;
}
} }
Ok(()) Ok(())