github.com/cilki/sh@v2.6.4+incompatible/expand/braces.go (about)

     1  // Copyright (c) 2018, Daniel Martí <mvdan@mvdan.cc>
     2  // See LICENSE for licensing information
     3  
     4  package expand
     5  
     6  import "mvdan.cc/sh/syntax"
     7  
     8  // Braces performs Bash brace expansion on words. For example, passing it a
     9  // literal word "foo{bar,baz}" will return two literal words, "foobar" and
    10  // "foobaz".
    11  //
    12  // It does not return an error; malformed brace expansions are simply skipped.
    13  // For example, "a{b{c,d}" results in the words "a{bc" and "a{bd".
    14  //
    15  // Note that the resulting words may have more word parts than necessary, such
    16  // as contiguous *syntax.Lit nodes, and that these parts may be shared between
    17  // words.
    18  func Braces(words ...*syntax.Word) []*syntax.Word {
    19  	var res []*syntax.Word
    20  	for _, word := range words {
    21  		res = append(res, syntax.ExpandBraces(word)...)
    22  	}
    23  	return res
    24  }