MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / Get

Method Get

cli/pkg/ssh_config/config.go:346–376  ·  view source on GitHub ↗

Get finds the first value in the configuration that matches the alias and contains key. Get returns the empty string if no value was found, or if the Config contains an invalid conditional Include value. The match for key is case insensitive.

(alias, key string)

Source from the content-addressed store, hash-verified

344//
345// The match for key is case insensitive.
346func (c *Config) Get(alias, key string) (string, error) {
347 lowerKey := strings.ToLower(key)
348 for _, host := range c.Hosts {
349 if !host.Matches(alias) {
350 continue
351 }
352 for _, node := range host.Nodes {
353 switch t := node.(type) {
354 case *Empty:
355 continue
356 case *KV:
357 // "keys are case insensitive" per the spec
358 lkey := strings.ToLower(t.Key)
359 if lkey == "match" {
360 panic("can't handle Match directives")
361 }
362 if lkey == lowerKey {
363 return t.Value, nil
364 }
365 case *Include:
366 val := t.Get(alias, key)
367 if val != "" {
368 return val, nil
369 }
370 default:
371 return "", fmt.Errorf("unknown Node type %v", t)
372 }
373 }
374 }
375 return "", nil
376}
377
378// GetAll returns all values in the configuration that match the alias and
379// contains key, or nil if none are present.

Callers 3

findValFunction · 0.45
GetFunction · 0.45
GetMethod · 0.45

Calls 1

MatchesMethod · 0.80

Tested by

no test coverage detected