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
<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 send the the contents of `file`.
@ -36,7 +36,7 @@ enum Args {
Server,
Client(String, bool),
Browse(String),
Clip(String),
Clip(Option<String>),
Error,
}
@ -77,9 +77,9 @@ fn parse_args(args: Vec<String>) -> 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<String>) {
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]

View file

@ -59,13 +59,17 @@ async fn clip_reader<T: AsyncRead + Unpin>(reader: &mut T) -> Result<()> {
}
#[inline]
pub async fn clip_file(file: &str) -> Result<()> {
if file == "-" {
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?;
} else {
let mut file = tokio::fs::File::open(file).await?;
clip_reader(&mut file).await?;
}
}
Ok(())