Matches returns true if the Host matches for the given alias. For a description of the rules that provide a match, see the manpage for ssh_config.
(alias string)
| 517 | // a description of the rules that provide a match, see the manpage for |
| 518 | // ssh_config. |
| 519 | func (h *Host) Matches(alias string) bool { |
| 520 | found := false |
| 521 | for i := range h.Patterns { |
| 522 | if h.Patterns[i].regex.MatchString(alias) { |
| 523 | if h.Patterns[i].not { |
| 524 | // Negated match. "A pattern entry may be negated by prefixing |
| 525 | // it with an exclamation mark (`!'). If a negated entry is |
| 526 | // matched, then the Host entry is ignored, regardless of |
| 527 | // whether any other patterns on the line match. Negated matches |
| 528 | // are therefore useful to provide exceptions for wildcard |
| 529 | // matches." |
| 530 | return false |
| 531 | } |
| 532 | found = true |
| 533 | } |
| 534 | } |
| 535 | return found |
| 536 | } |
| 537 | |
| 538 | // String prints h as it would appear in a config file. Minor tweaks may be |
| 539 | // present in the whitespace in the printed file. |