github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/network/debinterfaces/wordexp.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package debinterfaces
     5  
     6  import "path/filepath"
     7  
     8  // WordExpander performs word expansion like a posix-shell.
     9  type WordExpander interface {
    10  	// Expand pattern into a slice of words, or an error if the
    11  	// underlying implementation failed.
    12  	Expand(pattern string) ([]string, error)
    13  }
    14  
    15  var _ WordExpander = (*globber)(nil)
    16  
    17  type globber struct{}
    18  
    19  func newWordExpander() WordExpander {
    20  	return &globber{}
    21  }
    22  
    23  func (g *globber) Expand(pattern string) ([]string, error) {
    24  	// The ifupdown package natively used wordexp(3). For the
    25  	// cases we currently need to cater for we can (probably) get
    26  	// away by just globbing. wordexp(3) caters for a lot of
    27  	// shell-style expansions but I haven't seen examples of those
    28  	// in all the ENI files I have seen.
    29  	return filepath.Glob(pattern)
    30  }