vendor: add mattn/go-shellwords
authorCasey Callendrello <casey.callendrello@coreos.com>
Wed, 31 May 2017 17:20:27 +0000 (19:20 +0200)
committerCasey Callendrello <casey.callendrello@coreos.com>
Wed, 31 May 2017 17:21:03 +0000 (19:21 +0200)
Godeps/Godeps.json
vendor/github.com/mattn/go-shellwords/.travis.yml [new file with mode: 0644]
vendor/github.com/mattn/go-shellwords/LICENSE [new file with mode: 0644]
vendor/github.com/mattn/go-shellwords/README.md [new file with mode: 0644]
vendor/github.com/mattn/go-shellwords/shellwords.go [new file with mode: 0644]
vendor/github.com/mattn/go-shellwords/util_posix.go [new file with mode: 0644]
vendor/github.com/mattn/go-shellwords/util_windows.go [new file with mode: 0644]

index 5875159..dfe930d 100644 (file)
                        "ImportPath": "github.com/d2g/dhcp4client",
                        "Rev": "bed07e1bc5b85f69c6f0fd73393aa35ec68ed892"
                },
+               {
+                       "ImportPath": "github.com/mattn/go-shellwords",
+                       "Comment": "v1.0.3",
+                       "Rev": "02e3cf038dcea8290e44424da473dd12be796a8a"
+               },
                {
                        "ImportPath": "github.com/onsi/ginkgo",
                        "Comment": "v1.2.0-29-g7f8ab55",
diff --git a/vendor/github.com/mattn/go-shellwords/.travis.yml b/vendor/github.com/mattn/go-shellwords/.travis.yml
new file mode 100644 (file)
index 0000000..16d1430
--- /dev/null
@@ -0,0 +1,8 @@
+language: go
+go:
+  - tip
+before_install:
+  - go get github.com/mattn/goveralls
+  - go get golang.org/x/tools/cmd/cover
+script:
+    - $HOME/gopath/bin/goveralls -repotoken 2FMhp57u8LcstKL9B190fLTcEnBtAAiEL
diff --git a/vendor/github.com/mattn/go-shellwords/LICENSE b/vendor/github.com/mattn/go-shellwords/LICENSE
new file mode 100644 (file)
index 0000000..740fa93
--- /dev/null
@@ -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/vendor/github.com/mattn/go-shellwords/README.md b/vendor/github.com/mattn/go-shellwords/README.md
new file mode 100644 (file)
index 0000000..b1d235c
--- /dev/null
@@ -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/vendor/github.com/mattn/go-shellwords/shellwords.go b/vendor/github.com/mattn/go-shellwords/shellwords.go
new file mode 100644 (file)
index 0000000..1078039
--- /dev/null
@@ -0,0 +1,145 @@
+package shellwords
+
+import (
+       "errors"
+       "os"
+       "regexp"
+)
+
+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(s string) string {
+       return envRe.ReplaceAllStringFunc(s, func(s string) string {
+               s = s[1:]
+               if s[0] == '{' {
+                       s = s[1 : len(s)-1]
+               }
+               return os.Getenv(s)
+       })
+}
+
+type Parser struct {
+       ParseEnv      bool
+       ParseBacktick bool
+       Position      int
+}
+
+func NewParser() *Parser {
+       return &Parser{ParseEnv, ParseBacktick, 0}
+}
+
+func (p *Parser) Parse(line string) ([]string, error) {
+       args := []string{}
+       buf := ""
+       var escaped, doubleQuoted, singleQuoted, backQuote 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 {
+                               buf += string(r)
+                               backtick += string(r)
+                       } else if got {
+                               if p.ParseEnv {
+                                       buf = replaceEnv(buf)
+                               }
+                               args = append(args, buf)
+                               buf = ""
+                               got = false
+                       }
+                       continue
+               }
+
+               switch r {
+               case '`':
+                       if !singleQuoted && !doubleQuoted {
+                               if p.ParseBacktick {
+                                       if backQuote {
+                                               out, err := shellRun(backtick)
+                                               if err != nil {
+                                                       return nil, err
+                                               }
+                                               buf = out
+                                       }
+                                       backtick = ""
+                                       backQuote = !backQuote
+                                       continue
+                               }
+                               backtick = ""
+                               backQuote = !backQuote
+                       }
+               case '"':
+                       if !singleQuoted {
+                               doubleQuoted = !doubleQuoted
+                               continue
+                       }
+               case '\'':
+                       if !doubleQuoted {
+                               singleQuoted = !singleQuoted
+                               continue
+                       }
+               case ';', '&', '|', '<', '>':
+                       if !(escaped || singleQuoted || doubleQuoted || backQuote) {
+                               pos = i
+                               break loop
+                       }
+               }
+
+               got = true
+               buf += string(r)
+               if backQuote {
+                       backtick += string(r)
+               }
+       }
+
+       if got {
+               if p.ParseEnv {
+                       buf = replaceEnv(buf)
+               }
+               args = append(args, buf)
+       }
+
+       if escaped || singleQuoted || doubleQuoted || backQuote {
+               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/vendor/github.com/mattn/go-shellwords/util_posix.go b/vendor/github.com/mattn/go-shellwords/util_posix.go
new file mode 100644 (file)
index 0000000..4f8ac55
--- /dev/null
@@ -0,0 +1,19 @@
+// +build !windows
+
+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 {
+               return "", errors.New(err.Error() + ":" + string(b))
+       }
+       return strings.TrimSpace(string(b)), nil
+}
diff --git a/vendor/github.com/mattn/go-shellwords/util_windows.go b/vendor/github.com/mattn/go-shellwords/util_windows.go
new file mode 100644 (file)
index 0000000..7cad4cf
--- /dev/null
@@ -0,0 +1,17 @@
+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 {
+               return "", errors.New(err.Error() + ":" + string(b))
+       }
+       return strings.TrimSpace(string(b)), nil
+}