Skip to content

Commit

Permalink
fix: Avoid unexpected-rewriting for unmatched Hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
quag-cactus committed Jan 23, 2023
1 parent d56ddd7 commit 996061d
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,37 @@ func rewriteCfg(cfg *ssh_config.Config, targetPtn string, inputHostName string)
break
}
}
}

if !isContainedWildCard {
for _, node := range host.Nodes {

kv, ok := node.(*ssh_config.KV)

if ok && kv.Key == "HostName" {
previousHostName := kv.Value
kv.Value = inputHostName
//kv.Comment = "This value was rewritten automatically"
fmt.Printf("Hostname rewrited: %s -> %s (ln: %d)\n",
previousHostName, kv.Value, kv.Pos().Line)

rewrited = true
break
// rewriting
if !isContainedWildCard {
for _, node := range host.Nodes {

kv, ok := node.(*ssh_config.KV)

if ok && kv.Key == "HostName" {
previousHostName := kv.Value
kv.Value = inputHostName
//kv.Comment = "This value was rewritten automatically"
fmt.Printf("Hostname rewrited: %s -> %s (ln: %d)\n",
previousHostName, kv.Value, kv.Pos().Line)

rewrited = true
break
}
}
}

// Add new Host-Pattern if config has no targetd hostname
if !rewrited {
fmt.Println("adding Node...")
newNode := &ssh_config.KV{
Key: "HostName",
Value: inputHostName,
//Comment: "This value was added automatically",

// Add new Host-Pattern if config has no targetd hostname
if !rewrited {
fmt.Println("adding Node...")
newNode := &ssh_config.KV{
Key: "HostName",
Value: inputHostName,
//Comment: "This value was added automatically",
}
host.Nodes = append(host.Nodes, newNode)
}
host.Nodes = append(host.Nodes, newNode)

}

}

}
Expand Down

0 comments on commit 996061d

Please sign in to comment.