Skip to content

Commit

Permalink
feat: support user@host syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyscot committed Oct 25, 2024
1 parent a35120c commit fd7aab7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub(crate) struct CliArgs {
pub initial_congestion_window: Option<u64>,

// POSITIONAL ARGUMENTS ================================================================
/// The source file. This may be a local filename, or remote specified as HOST:FILE.
/// The source file. This may be a local filename, or remote specified as HOST:FILE or USER@HOST:FILE.
#[arg(
conflicts_with_all(MODE_OPTIONS),
required = true,
Expand All @@ -143,7 +143,7 @@ pub(crate) struct CliArgs {
pub source: Option<FileSpec>,

/// Destination. This may be a file or directory. It may be local or remote
/// (specified as HOST:DESTINATION, or simply HOST: to copy to your home directory there).
/// (specified as HOST:DESTINATION or USER@HOST:DESTINATION; or simply HOST: or USER@HOST: to copy to your home directory there).
#[arg(
conflicts_with_all(MODE_OPTIONS),
required = true,
Expand All @@ -163,7 +163,7 @@ impl CliArgs {
}
}

pub(crate) fn remote_host(&self) -> anyhow::Result<&str> {
pub(crate) fn remote_user_host(&self) -> anyhow::Result<&str> {
let src = self.source.as_ref().ok_or(anyhow::anyhow!(
"both source and destination must be specified"
))?;
Expand All @@ -176,6 +176,13 @@ impl CliArgs {
.unwrap_or_else(|| dest.host.as_ref().unwrap()))
}

pub(crate) fn remote_host(&self) -> anyhow::Result<&str> {
let user_host = self.remote_user_host()?;
// It might be user@host, or it might be just the hostname or IP.
let (_, host) = user_host.split_once('@').unwrap_or(("", user_host));
Ok(host)
}

/// Convenience wrapper that returns the active value to use for outbound bandwidth
pub(crate) fn bandwidth_outbound_active(&self) -> u64 {
self.bandwidth_outbound.unwrap_or(self.bandwidth).size()
Expand Down
6 changes: 3 additions & 3 deletions src/client/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
/// The parameter set needed to set up the control channel
#[derive(Debug)]
pub struct Parameters {
remote_host: String,
remote_user_host: String,
remote_debug: bool,
remote_tx_bw_bytes: u64,
remote_rx_bw_bytes: u64,
Expand All @@ -33,7 +33,7 @@ impl TryFrom<&CliArgs> for Parameters {

fn try_from(args: &CliArgs) -> std::result::Result<Self, Self::Error> {
Ok(Self {
remote_host: args.remote_host()?.to_string(),
remote_user_host: args.remote_user_host()?.to_string(),
remote_debug: args.remote_debug,
// Note that we flip inbound and outbound here as we're computing parameters to give to the remote
remote_rx_bw_bytes: args.bandwidth_outbound_active(),
Expand Down Expand Up @@ -101,7 +101,7 @@ impl ControlChannel {
AddressFamily::IPv6 => server.arg("-6"),
};
let _ = server.args([
&args.remote_host,
&args.remote_user_host,
"qcp",
"--server",
"-b",
Expand Down

0 comments on commit fd7aab7

Please sign in to comment.