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

Function NewInclude

cli/pkg/ssh_config/config.go:682–722  ·  view source on GitHub ↗

NewInclude creates a new Include with a list of file globs to include. Configuration files are parsed greedily (e.g. as soon as this function runs). Any error encountered while parsing nested configuration files will be returned.

(directives []string, hasEquals bool, pos Position, comment string, system bool, depth uint8)

Source from the content-addressed store, hash-verified

680// Any error encountered while parsing nested configuration files will be
681// returned.
682func NewInclude(directives []string, hasEquals bool, pos Position, comment string, system bool, depth uint8) (*Include, error) {
683 if depth > maxRecurseDepth {
684 return nil, ErrDepthExceeded
685 }
686 inc := &Include{
687 Comment: comment,
688 directives: directives,
689 files: make(map[string]*Config),
690 position: pos,
691 leadingSpace: pos.Col - 1,
692 depth: depth,
693 hasEquals: hasEquals,
694 }
695 // no need for inc.mu.Lock() since nothing else can access this inc
696 matches := make([]string, 0)
697 for i := range directives {
698 var path string
699 if filepath.IsAbs(directives[i]) {
700 path = directives[i]
701 } else if system {
702 path = filepath.Join("/etc/ssh", directives[i])
703 } else {
704 path = filepath.Join(homedir(), ".ssh", directives[i])
705 }
706 theseMatches, err := filepath.Glob(path)
707 if err != nil {
708 return nil, err
709 }
710 matches = append(matches, theseMatches...)
711 }
712 matches = removeDups(matches)
713 inc.matches = matches
714 for i := range matches {
715 config, err := parseWithDepth(matches[i], depth)
716 if err != nil {
717 return nil, err
718 }
719 inc.files[matches[i]] = config
720 }
721 return inc, nil
722}
723
724// Pos returns the position of the Include directive in the larger file.
725func (i *Include) Pos() Position {

Callers 1

parseKVMethod · 0.85

Calls 5

homedirFunction · 0.85
removeDupsFunction · 0.85
parseWithDepthFunction · 0.85
GlobMethod · 0.80
JoinMethod · 0.45

Tested by

no test coverage detected