summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2019-05-24 02:21:06 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2019-05-24 02:21:29 +0300
commitc86081506c706c6230c247a2391f35d35130ca94 (patch)
tree4a23a95fd685150a0b6d38490583975e1f654312
parent48142b98ca9565698632c44e72e29e22b9c923c3 (diff)
downloadgitlab-shell-c86081506c706c6230c247a2391f35d35130ca94.tar.gz
Vendor mattn/go-shellwords
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/LICENSE21
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/README.md47
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/go.mod1
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/shellwords.go195
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/util_go15.go24
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/util_posix.go22
-rw-r--r--go/vendor/github.com/mattn/go-shellwords/util_windows.go22
-rw-r--r--go/vendor/vendor.json10
8 files changed, 342 insertions, 0 deletions
diff --git a/go/vendor/github.com/mattn/go-shellwords/LICENSE b/go/vendor/github.com/mattn/go-shellwords/LICENSE
new file mode 100644
index 0000000..740fa93
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 Yasuhiro Matsumoto
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/go/vendor/github.com/mattn/go-shellwords/README.md b/go/vendor/github.com/mattn/go-shellwords/README.md
new file mode 100644
index 0000000..b1d235c
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/README.md
@@ -0,0 +1,47 @@
+# go-shellwords
+
+[![Coverage Status](https://coveralls.io/repos/mattn/go-shellwords/badge.png?branch=master)](https://coveralls.io/r/mattn/go-shellwords?branch=master)
+[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords)
+
+Parse line as shell words.
+
+## Usage
+
+```go
+args, err := shellwords.Parse("./foo --bar=baz")
+// args should be ["./foo", "--bar=baz"]
+```
+
+```go
+os.Setenv("FOO", "bar")
+p := shellwords.NewParser()
+p.ParseEnv = true
+args, err := p.Parse("./foo $FOO")
+// args should be ["./foo", "bar"]
+```
+
+```go
+p := shellwords.NewParser()
+p.ParseBacktick = true
+args, err := p.Parse("./foo `echo $SHELL`")
+// args should be ["./foo", "/bin/bash"]
+```
+
+```go
+shellwords.ParseBacktick = true
+p := shellwords.NewParser()
+args, err := p.Parse("./foo `echo $SHELL`")
+// args should be ["./foo", "/bin/bash"]
+```
+
+# Thanks
+
+This is based on cpan module [Parse::CommandLine](https://metacpan.org/pod/Parse::CommandLine).
+
+# License
+
+under the MIT License: http://mattn.mit-license.org/2017
+
+# Author
+
+Yasuhiro Matsumoto (a.k.a mattn)
diff --git a/go/vendor/github.com/mattn/go-shellwords/go.mod b/go/vendor/github.com/mattn/go-shellwords/go.mod
new file mode 100644
index 0000000..8d96dbd
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/go.mod
@@ -0,0 +1 @@
+module github.com/mattn/go-shellwords
diff --git a/go/vendor/github.com/mattn/go-shellwords/shellwords.go b/go/vendor/github.com/mattn/go-shellwords/shellwords.go
new file mode 100644
index 0000000..cf42b40
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/shellwords.go
@@ -0,0 +1,195 @@
+package shellwords
+
+import (
+ "errors"
+ "os"
+ "regexp"
+ "strings"
+)
+
+var (
+ ParseEnv bool = false
+ ParseBacktick bool = false
+)
+
+var envRe = regexp.MustCompile(`\$({[a-zA-Z0-9_]+}|[a-zA-Z0-9_]+)`)
+
+func isSpace(r rune) bool {
+ switch r {
+ case ' ', '\t', '\r', '\n':
+ return true
+ }
+ return false
+}
+
+func replaceEnv(getenv func(string) string, s string) string {
+ if getenv == nil {
+ getenv = os.Getenv
+ }
+
+ return envRe.ReplaceAllStringFunc(s, func(s string) string {
+ s = s[1:]
+ if s[0] == '{' {
+ s = s[1 : len(s)-1]
+ }
+ return getenv(s)
+ })
+}
+
+type Parser struct {
+ ParseEnv bool
+ ParseBacktick bool
+ Position int
+
+ // If ParseEnv is true, use this for getenv.
+ // If nil, use os.Getenv.
+ Getenv func(string) string
+}
+
+func NewParser() *Parser {
+ return &Parser{
+ ParseEnv: ParseEnv,
+ ParseBacktick: ParseBacktick,
+ Position: 0,
+ }
+}
+
+func (p *Parser) Parse(line string) ([]string, error) {
+ args := []string{}
+ buf := ""
+ var escaped, doubleQuoted, singleQuoted, backQuote, dollarQuote bool
+ backtick := ""
+
+ pos := -1
+ got := false
+
+loop:
+ for i, r := range line {
+ if escaped {
+ buf += string(r)
+ escaped = false
+ continue
+ }
+
+ if r == '\\' {
+ if singleQuoted {
+ buf += string(r)
+ } else {
+ escaped = true
+ }
+ continue
+ }
+
+ if isSpace(r) {
+ if singleQuoted || doubleQuoted || backQuote || dollarQuote {
+ buf += string(r)
+ backtick += string(r)
+ } else if got {
+ if p.ParseEnv {
+ buf = replaceEnv(p.Getenv, buf)
+ }
+ args = append(args, buf)
+ buf = ""
+ got = false
+ }
+ continue
+ }
+
+ switch r {
+ case '`':
+ if !singleQuoted && !doubleQuoted && !dollarQuote {
+ if p.ParseBacktick {
+ if backQuote {
+ out, err := shellRun(backtick)
+ if err != nil {
+ return nil, err
+ }
+ buf = buf[:len(buf)-len(backtick)] + out
+ }
+ backtick = ""
+ backQuote = !backQuote
+ continue
+ }
+ backtick = ""
+ backQuote = !backQuote
+ }
+ case ')':
+ if !singleQuoted && !doubleQuoted && !backQuote {
+ if p.ParseBacktick {
+ if dollarQuote {
+ out, err := shellRun(backtick)
+ if err != nil {
+ return nil, err
+ }
+ if r == ')' {
+ buf = buf[:len(buf)-len(backtick)-2] + out
+ } else {
+ buf = buf[:len(buf)-len(backtick)-1] + out
+ }
+ }
+ backtick = ""
+ dollarQuote = !dollarQuote
+ continue
+ }
+ backtick = ""
+ dollarQuote = !dollarQuote
+ }
+ case '(':
+ if !singleQuoted && !doubleQuoted && !backQuote {
+ if !dollarQuote && strings.HasSuffix(buf, "$") {
+ dollarQuote = true
+ buf += "("
+ continue
+ } else {
+ return nil, errors.New("invalid command line string")
+ }
+ }
+ case '"':
+ if !singleQuoted && !dollarQuote {
+ doubleQuoted = !doubleQuoted
+ continue
+ }
+ case '\'':
+ if !doubleQuoted && !dollarQuote {
+ singleQuoted = !singleQuoted
+ continue
+ }
+ case ';', '&', '|', '<', '>':
+ if !(escaped || singleQuoted || doubleQuoted || backQuote) {
+ if r == '>' && len(buf) > 0 {
+ if c := buf[0]; '0' <= c && c <= '9' {
+ i -= 1
+ got = false
+ }
+ }
+ pos = i
+ break loop
+ }
+ }
+
+ got = true
+ buf += string(r)
+ if backQuote || dollarQuote {
+ backtick += string(r)
+ }
+ }
+
+ if got {
+ if p.ParseEnv {
+ buf = replaceEnv(p.Getenv, buf)
+ }
+ args = append(args, buf)
+ }
+
+ if escaped || singleQuoted || doubleQuoted || backQuote || dollarQuote {
+ return nil, errors.New("invalid command line string")
+ }
+
+ p.Position = pos
+
+ return args, nil
+}
+
+func Parse(line string) ([]string, error) {
+ return NewParser().Parse(line)
+}
diff --git a/go/vendor/github.com/mattn/go-shellwords/util_go15.go b/go/vendor/github.com/mattn/go-shellwords/util_go15.go
new file mode 100644
index 0000000..180f00f
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/util_go15.go
@@ -0,0 +1,24 @@
+// +build !go1.6
+
+package shellwords
+
+import (
+ "os"
+ "os/exec"
+ "runtime"
+ "strings"
+)
+
+func shellRun(line string) (string, error) {
+ var b []byte
+ var err error
+ if runtime.GOOS == "windows" {
+ b, err = exec.Command(os.Getenv("COMSPEC"), "/c", line).Output()
+ } else {
+ b, err = exec.Command(os.Getenv("SHELL"), "-c", line).Output()
+ }
+ if err != nil {
+ return "", err
+ }
+ return strings.TrimSpace(string(b)), nil
+}
diff --git a/go/vendor/github.com/mattn/go-shellwords/util_posix.go b/go/vendor/github.com/mattn/go-shellwords/util_posix.go
new file mode 100644
index 0000000..eaf1011
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/util_posix.go
@@ -0,0 +1,22 @@
+// +build !windows,go1.6
+
+package shellwords
+
+import (
+ "errors"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+func shellRun(line string) (string, error) {
+ shell := os.Getenv("SHELL")
+ b, err := exec.Command(shell, "-c", line).Output()
+ if err != nil {
+ if eerr, ok := err.(*exec.ExitError); ok {
+ b = eerr.Stderr
+ }
+ return "", errors.New(err.Error() + ":" + string(b))
+ }
+ return strings.TrimSpace(string(b)), nil
+}
diff --git a/go/vendor/github.com/mattn/go-shellwords/util_windows.go b/go/vendor/github.com/mattn/go-shellwords/util_windows.go
new file mode 100644
index 0000000..e46f89a
--- /dev/null
+++ b/go/vendor/github.com/mattn/go-shellwords/util_windows.go
@@ -0,0 +1,22 @@
+// +build windows,go1.6
+
+package shellwords
+
+import (
+ "errors"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+func shellRun(line string) (string, error) {
+ shell := os.Getenv("COMSPEC")
+ b, err := exec.Command(shell, "/c", line).Output()
+ if err != nil {
+ if eerr, ok := err.(*exec.ExitError); ok {
+ b = eerr.Stderr
+ }
+ return "", errors.New(err.Error() + ":" + string(b))
+ }
+ return strings.TrimSpace(string(b)), nil
+}
diff --git a/go/vendor/vendor.json b/go/vendor/vendor.json
index 6e9a1a4..51d6774 100644
--- a/go/vendor/vendor.json
+++ b/go/vendor/vendor.json
@@ -84,6 +84,12 @@
"revision": "c0184d44cb322c9d9abcaebb2139dc754b3c0145"
},
{
+ "checksumSHA1": "AZtrc8Chiynrp48VQzRDH5vBR3M=",
+ "path": "github.com/mattn/go-shellwords",
+ "revision": "2444a32a19f450fabaa0bb3e96a703f15d9a97d2",
+ "revisionTime": "2019-04-25T16:15:01Z"
+ },
+ {
"checksumSHA1": "a/DHmc9bdsYlZZcwp6i3xhvV7Pk=",
"path": "github.com/opentracing/opentracing-go",
"revision": "25a84ff92183e2f8ac018ba1db54f8a07b3c0e04",
@@ -640,6 +646,10 @@
"revisionTime": "2017-04-07T17:21:22Z"
},
{
+ "path": "https://github.com/mattn/go-shellwords",
+ "revision": ""
+ },
+ {
"path": "https://github.com/otiai10/copy",
"revision": ""
}