Skip to content

Commit

Permalink
fix(ui): host name is the hostname if not specified
Browse files Browse the repository at this point in the history
Closes #77

Signed-off-by: Nathanael DEMACON <[email protected]>
  • Loading branch information
quantumsheep committed Mar 4, 2024
1 parent 71416dd commit e927668
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ pub fn parse_config(raw_path: &String) -> Result<Vec<Host>> {
let hosts = ssh_config::Parser::new()
.parse_file(path)?
.apply_patterns()
.apply_name_to_empty_hostname()
.merge_same_hosts()
.iter()
.filter(|host| host.get(&ssh_config::EntryType::Hostname).is_some())
.map(|host| Host {
name: host
.get_patterns()
Expand Down
14 changes: 14 additions & 0 deletions src/ssh_config/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ impl Host {

#[allow(clippy::module_name_repetitions)]
pub trait HostVecExt {
/// Apply the name entry to the hostname entry if the hostname entry is empty.
fn apply_name_to_empty_hostname(&mut self) -> &mut Self;

/// Merges the hosts with the same entries into one host.
fn merge_same_hosts(&mut self) -> &mut Self;

Expand All @@ -103,6 +106,17 @@ pub trait HostVecExt {
}

impl HostVecExt for Vec<Host> {
fn apply_name_to_empty_hostname(&mut self) -> &mut Self {
for host in self.iter_mut() {
if host.get(&EntryType::Hostname).is_none() {
let name = host.patterns.first().unwrap().clone();
host.update((EntryType::Hostname, name.clone()));
}
}

self
}

fn merge_same_hosts(&mut self) -> &mut Self {
for i in (0..self.len()).rev() {
for j in (0..i).rev() {
Expand Down

0 comments on commit e927668

Please sign in to comment.