feat: ssh.rs
This commit is contained in:
@@ -45,11 +45,9 @@ impl SshConfig {
|
|||||||
for (k, v) in &self.profiles {
|
for (k, v) in &self.profiles {
|
||||||
if k == profile {
|
if k == profile {
|
||||||
found.push((k, v));
|
found.push((k, v));
|
||||||
} else {
|
} else if let Some(alias) = &v.alias {
|
||||||
if let Some(alias) = &v.alias {
|
if alias.contains(&profile.to_string()) {
|
||||||
if alias.contains(&profile.to_string()) {
|
found.push((k, v));
|
||||||
found.push((k, v));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,13 +77,10 @@ fn main() -> XResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (profile_id, profile) in &ssh_rs_config.profiles {
|
for (profile_id, profile) in &ssh_rs_config.profiles {
|
||||||
let mut features = vec![];
|
let features = make_features(
|
||||||
if let Some(true) = profile.forward_agent {
|
profile.forward_agent.unwrap_or(false),
|
||||||
features.push("forward_agent");
|
profile.proxy.unwrap_or(false),
|
||||||
}
|
);
|
||||||
if let Some(true) = profile.proxy {
|
|
||||||
features.push("proxy");
|
|
||||||
}
|
|
||||||
println!(
|
println!(
|
||||||
"- {} : {}{} {}{}{} # {}{}",
|
"- {} : {}{} {}{}{} # {}{}",
|
||||||
pad(profile_id, max_profile_id_len),
|
pad(profile_id, max_profile_id_len),
|
||||||
@@ -106,21 +101,18 @@ fn main() -> XResult<()> {
|
|||||||
},
|
},
|
||||||
util_term::END,
|
util_term::END,
|
||||||
profile.comment.clone().unwrap_or_else(|| "-".to_string()),
|
profile.comment.clone().unwrap_or_else(|| "-".to_string()),
|
||||||
if features.is_empty() {
|
iff!(
|
||||||
"".to_string()
|
features.is_empty(),
|
||||||
} else {
|
"".to_string(),
|
||||||
format!(" ;[{}]", features.join(", "))
|
format!(" ;[{}]", features.join(", "))
|
||||||
}
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut features = vec![];
|
let features = make_features(
|
||||||
if let Some(true) = ssh_rs_config.default_forward_agent {
|
ssh_rs_config.default_forward_agent.unwrap_or(false),
|
||||||
features.push("forward_agent");
|
ssh_rs_config.default_proxy.unwrap_or(false),
|
||||||
}
|
);
|
||||||
if let Some(true) = ssh_rs_config.default_proxy {
|
|
||||||
features.push("proxy");
|
|
||||||
}
|
|
||||||
if !features.is_empty() {
|
if !features.is_empty() {
|
||||||
println!();
|
println!();
|
||||||
information!("Global default features: [{}]", features.join(", "));
|
information!("Global default features: [{}]", features.join(", "));
|
||||||
@@ -205,6 +197,17 @@ fn pad(str: &str, width: usize) -> String {
|
|||||||
format!("{}{}", str, " ".repeat(width - str.len()))
|
format!("{}{}", str, " ".repeat(width - str.len()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_features(forward_agent: bool, proxy: bool) -> Vec<String> {
|
||||||
|
let mut features = vec![];
|
||||||
|
if forward_agent {
|
||||||
|
features.push("forward_agent".to_string());
|
||||||
|
}
|
||||||
|
if proxy {
|
||||||
|
features.push("proxy".to_string());
|
||||||
|
}
|
||||||
|
features
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_username_and_host(username_and_host: &str) -> XResult<(Option<String>, String)> {
|
fn parse_username_and_host(username_and_host: &str) -> XResult<(Option<String>, String)> {
|
||||||
if username_and_host.is_empty() {
|
if username_and_host.is_empty() {
|
||||||
return simple_error!("Empty username@host");
|
return simple_error!("Empty username@host");
|
||||||
|
|||||||
Reference in New Issue
Block a user