Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to pass in a custom port #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::{Path, PathBuf};
use std::process::{exit, Command, Stdio};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::process::{exit, Command, Stdio};
use structopt::StructOpt;
use toml::Value;

Expand All @@ -17,6 +17,13 @@ enum Opts {
#[structopt(short = "r", long = "remote", help = "Remote ssh build server")]
remote: Option<String>,

#[structopt(
short = "p",
long = "port",
help = "Custom port for ssh on the build server"
)]
port: Option<String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Option<u16>, a String allows too many invalid inputs. This would also make port Copy, avoiding al these clone()s.


#[structopt(
short = "b",
long = "build-env",
Expand Down Expand Up @@ -112,6 +119,7 @@ fn main() {

let Opts::Remote {
remote,
port,
build_env,
rustup_default,
env,
Expand Down Expand Up @@ -154,7 +162,7 @@ fn main() {
// generate a unique build path by using the hashed project dir as folder on the remote machine
let mut hasher = DefaultHasher::new();
project_dir.hash(&mut hasher);
let build_path = format!("~/remote-builds/{}/", hasher.finish());
let build_path = format!("~/remote-builds/{}", hasher.finish());

info!("Transferring sources to build server.");
// transfer project to build server
Expand All @@ -163,6 +171,11 @@ fn main() {
.arg("-a".to_owned())
.arg("--delete")
.arg("--compress")
.arg(if port.is_some() {
format!("-e ssh -p {}", port.clone().unwrap())
} else {
"".to_string()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit of an ugly hack. You could use .args() here, which accepts T: IntoIterator<…>. Option does implement IntoIterator (just map the port).

})
.arg("--info=progress2")
.arg("--exclude")
.arg("target");
Expand Down Expand Up @@ -199,6 +212,11 @@ fn main() {

info!("Starting build process.");
let output = Command::new("ssh")
.arg(if port.is_some() {
format!("-p {}", port.clone().unwrap())
} else {
"".to_string()
})
.arg("-t")
.arg(&build_server)
.arg(build_command)
Expand All @@ -218,9 +236,21 @@ fn main() {
.arg("-a")
.arg("--delete")
.arg("--compress")
.arg(if port.is_some() {
format!("-e ssh -p {}", port.clone().unwrap())
} else {
"".to_string()
})
.arg("--info=progress2")
.arg(format!("{}:{}/target/{}", build_server, build_path, file_name))
.arg(format!("{}/target/{}", project_dir.to_string_lossy(), file_name))
.arg(format!(
"{}:{}/target/{}",
build_server, build_path, file_name
))
.arg(format!(
"{}/target/{}",
project_dir.to_string_lossy(),
file_name
))
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.stdin(Stdio::inherit())
Expand All @@ -240,6 +270,11 @@ fn main() {
.arg("-a")
.arg("--delete")
.arg("--compress")
.arg(if port.is_some() {
format!("-e ssh -p {}", port.clone().unwrap())
} else {
"".to_string()
})
.arg("--info=progress2")
.arg(format!("{}:{}/Cargo.lock", build_server, build_path))
.arg(format!("{}/Cargo.lock", project_dir.to_string_lossy()))
Expand Down