upgrade envsubst
This commit is contained in:
parent
f0cbe62d81
commit
dbdb0c3906
5 changed files with 68 additions and 13 deletions
4
vendor/github.com/drone/envsubst/README
generated
vendored
4
vendor/github.com/drone/envsubst/README
generated
vendored
|
@ -1,8 +1,8 @@
|
|||
Go package emulates bash environment variable substitution in a string using ${var} syntax. Includes support for bash string replacement functions.
|
||||
Go package for expanding variables in a string using ${var} syntax. Includes support for bash string replacement functions.
|
||||
|
||||
Documentation:
|
||||
|
||||
http://godoc.org/github.com/drone/env
|
||||
http://godoc.org/github.com/drone/envsubst
|
||||
|
||||
Supported Functions:
|
||||
|
||||
|
|
58
vendor/github.com/drone/envsubst/funcs.go
generated
vendored
58
vendor/github.com/drone/envsubst/funcs.go
generated
vendored
|
@ -1,6 +1,7 @@
|
|||
package envsubst
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
@ -150,28 +151,77 @@ func replaceSuffix(s string, args ...string) string {
|
|||
|
||||
func trimShortestPrefix(s string, args ...string) string {
|
||||
if len(args) != 0 {
|
||||
s = strings.TrimPrefix(s, args[0])
|
||||
s = trimShortest(s, args[0])
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func trimShortestSuffix(s string, args ...string) string {
|
||||
if len(args) != 0 {
|
||||
s = strings.TrimSuffix(s, args[0])
|
||||
r := reverse(s)
|
||||
rarg := reverse(args[0])
|
||||
s = reverse(trimShortest(r, rarg))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func trimLongestPrefix(s string, args ...string) string {
|
||||
if len(args) != 0 {
|
||||
s = strings.TrimPrefix(s, args[0])
|
||||
s = trimLongest(s, args[0])
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func trimLongestSuffix(s string, args ...string) string {
|
||||
if len(args) != 0 {
|
||||
s = strings.TrimSuffix(s, args[0])
|
||||
r := reverse(s)
|
||||
rarg := reverse(args[0])
|
||||
s = reverse(trimLongest(r, rarg))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func trimShortest(s, arg string) string {
|
||||
var shortestMatch string
|
||||
for i :=0 ; i < len(s); i++ {
|
||||
match, err := path.Match(arg, s[0:len(s)-i])
|
||||
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
|
||||
if match {
|
||||
shortestMatch = s[0:len(s)-i]
|
||||
}
|
||||
}
|
||||
|
||||
if shortestMatch != "" {
|
||||
return strings.TrimPrefix(s, shortestMatch)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func trimLongest(s, arg string) string {
|
||||
for i :=0 ; i < len(s); i++ {
|
||||
match, err := path.Match(arg, s[0:len(s)-i])
|
||||
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
|
||||
if match {
|
||||
return strings.TrimPrefix(s, s[0:len(s)-i])
|
||||
}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func reverse(s string) string {
|
||||
r := []rune(s)
|
||||
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
|
||||
r[i], r[j] = r[j], r[i]
|
||||
}
|
||||
return string(r)
|
||||
}
|
||||
|
|
2
vendor/github.com/drone/envsubst/parse/parse.go
generated
vendored
2
vendor/github.com/drone/envsubst/parse/parse.go
generated
vendored
|
@ -30,7 +30,7 @@ func (t *Tree) Parse(buf string) (tree *Tree, err error) {
|
|||
|
||||
func (t *Tree) parseAny() (Node, error) {
|
||||
t.scanner.accept = acceptRune
|
||||
t.scanner.mode = scanIdent | scanLbrack
|
||||
t.scanner.mode = scanIdent | scanLbrack | scanEscape
|
||||
|
||||
switch t.scanner.scan() {
|
||||
case tokenIdent:
|
||||
|
|
5
vendor/github.com/drone/envsubst/parse/scan.go
generated
vendored
5
vendor/github.com/drone/envsubst/parse/scan.go
generated
vendored
|
@ -181,6 +181,11 @@ func (s *scanner) scanEscaped(r rune) bool {
|
|||
if s.mode&scanEscape == 0 {
|
||||
return false
|
||||
}
|
||||
if r == '$' {
|
||||
if s.peek() == '$' {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if r != '\\' {
|
||||
return false
|
||||
}
|
||||
|
|
12
vendor/vendor.json
vendored
12
vendor/vendor.json
vendored
|
@ -285,16 +285,16 @@
|
|||
"revisionTime": "2017-02-10T18:43:46Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "7tosn2Sxlubl+7ElXSZ6Mz8tAjY=",
|
||||
"checksumSHA1": "pjMV8mwWcQ0Kk9cbLWweTGiqYPk=",
|
||||
"path": "github.com/drone/envsubst",
|
||||
"revision": "3e65ae5fd2d944d56fdf52cb3f887247498d50e9",
|
||||
"revisionTime": "2017-01-18T15:01:55Z"
|
||||
"revision": "523de92ea410a5756012669fb628fe42a3056b3e",
|
||||
"revisionTime": "2017-03-25T05:49:59Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "LPKfsjm4AYVgCLVcAWnQdSpt5SA=",
|
||||
"checksumSHA1": "CVG/vocbXGLbGKRO//TOlicOBkw=",
|
||||
"path": "github.com/drone/envsubst/parse",
|
||||
"revision": "3e65ae5fd2d944d56fdf52cb3f887247498d50e9",
|
||||
"revisionTime": "2017-01-18T15:01:55Z"
|
||||
"revision": "523de92ea410a5756012669fb628fe42a3056b3e",
|
||||
"revisionTime": "2017-03-25T05:49:59Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "++oBqqmh8bt50iB6/I+BHnrzC80=",
|
||||
|
|
Loading…
Reference in a new issue