()
| 93 | } |
| 94 | |
| 95 | func (p *sshParser) parseKV() sshParserStateFn { |
| 96 | key := p.getToken() |
| 97 | hasEquals := false |
| 98 | val := p.getToken() |
| 99 | if val.typ == tokenEquals { |
| 100 | hasEquals = true |
| 101 | val = p.getToken() |
| 102 | } |
| 103 | comment := "" |
| 104 | tok := p.peek() |
| 105 | if tok == nil { |
| 106 | tok = &token{typ: tokenEOF} |
| 107 | } |
| 108 | if tok.typ == tokenComment && tok.Position.Line == val.Position.Line { |
| 109 | tok = p.getToken() |
| 110 | comment = tok.val |
| 111 | } |
| 112 | if strings.ToLower(key.val) == "match" { |
| 113 | // https://github.com/kevinburke/ssh_config/issues/6 |
| 114 | p.raiseErrorf(val, "ssh_config: Match directive parsing is unsupported") |
| 115 | return nil |
| 116 | } |
| 117 | if strings.ToLower(key.val) == "host" { |
| 118 | strPatterns := strings.Split(val.val, " ") |
| 119 | patterns := make([]*Pattern, 0) |
| 120 | for i := range strPatterns { |
| 121 | if strPatterns[i] == "" { |
| 122 | continue |
| 123 | } |
| 124 | pat, err := NewPattern(strPatterns[i]) |
| 125 | if err != nil { |
| 126 | p.raiseErrorf(val, "Invalid host pattern: %v", err) |
| 127 | return nil |
| 128 | } |
| 129 | patterns = append(patterns, pat) |
| 130 | } |
| 131 | // val.val at this point could be e.g. "example.com " |
| 132 | hostval := strings.TrimRightFunc(val.val, unicode.IsSpace) |
| 133 | spaceBeforeComment := val.val[len(hostval):] |
| 134 | val.val = hostval |
| 135 | p.config.Hosts = append(p.config.Hosts, &Host{ |
| 136 | Patterns: patterns, |
| 137 | Nodes: make([]Node, 0), |
| 138 | EOLComment: comment, |
| 139 | spaceBeforeComment: spaceBeforeComment, |
| 140 | hasEquals: hasEquals, |
| 141 | }) |
| 142 | return p.parseStart |
| 143 | } |
| 144 | lastHost := p.config.Hosts[len(p.config.Hosts)-1] |
| 145 | if strings.ToLower(key.val) == "include" { |
| 146 | inc, err := NewInclude(strings.Split(val.val, " "), hasEquals, key.Position, comment, p.system, p.depth+1) |
| 147 | if err == ErrDepthExceeded { |
| 148 | p.raiseError(val, err) |
| 149 | return nil |
| 150 | } |
| 151 | if err != nil { |
| 152 | p.raiseErrorf(val, "Error parsing Include directive: %v", err) |
nothing calls this directly
no test coverage detected