diff --git a/common.mk b/common.mk index eb26cf64c..5c77e672f 100644 --- a/common.mk +++ b/common.mk @@ -1,6 +1,6 @@ GO_ARGS ?= -a GO_REPO_ROOT := /go/src/github.com/dokku/dokku -BUILD_IMAGE := golang:1.12 +BUILD_IMAGE := golang:1.14.4 .PHONY: build-in-docker build clean src-clean @@ -12,6 +12,7 @@ build-in-docker: clean -v $$PWD/../..:$(GO_REPO_ROOT) \ -v /tmp/dokku-go-build-cache:/root/.cache \ -e PLUGIN_NAME=$(PLUGIN_NAME) \ + -e GO111MODULE=on \ -w $(GO_REPO_ROOT)/plugins/$(PLUGIN_NAME) \ $(BUILD_IMAGE) \ bash -c "GO_ARGS='$(GO_ARGS)' make -j4 build" || exit $$? diff --git a/plugins/apps/glide.yaml b/plugins/apps/glide.yaml deleted file mode 100644 index a720d6c11..000000000 --- a/plugins/apps/glide.yaml +++ /dev/null @@ -1,4 +0,0 @@ -package: . -import: -- package: github.com/codeskyblue/go-sh -- package: github.com/ryanuber/columnize diff --git a/plugins/apps/go.mod b/plugins/apps/go.mod new file mode 100644 index 000000000..c43805370 --- /dev/null +++ b/plugins/apps/go.mod @@ -0,0 +1,11 @@ +module github.com/dokku/dokku/plugins/apps + +go 1.14 + +require ( + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 // indirect + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 // indirect +) + +replace github.com/dokku/dokku/plugins/common => ../common diff --git a/plugins/apps/go.sum b/plugins/apps/go.sum new file mode 100644 index 000000000..6f9bd8d8d --- /dev/null +++ b/plugins/apps/go.sum @@ -0,0 +1,45 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/apps/src/commands/commands.go b/plugins/apps/src/commands/commands.go index e0313de10..0e38ebbd9 100644 --- a/plugins/apps/src/commands/commands.go +++ b/plugins/apps/src/commands/commands.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - columnize "github.com/ryanuber/columnize" ) const ( @@ -61,11 +60,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/apps/src/glide.lock b/plugins/apps/src/glide.lock deleted file mode 100644 index fe4a98f07..000000000 --- a/plugins/apps/src/glide.lock +++ /dev/null @@ -1,6 +0,0 @@ -hash: 1ddab5de41d1514c2722bd7e24758ad4b60bf6956eb5b9b925fa071a1427f149 -updated: 2017-01-03T17:16:50.97156327-08:00 -imports: -- name: github.com/ryanuber/columnize - version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360 -testImports: [] diff --git a/plugins/apps/src/glide.yaml b/plugins/apps/src/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/apps/src/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/apps/src/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/apps/src/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/apps/src/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/apps/src/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/apps/src/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/apps/src/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/apps/src/vendor/github.com/ryanuber/columnize/README.md b/plugins/apps/src/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/apps/src/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/apps/src/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/apps/src/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/apps/src/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/apps/src/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/apps/src/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/apps/src/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/apps/vendor/github.com/codegangsta/inject/.gitignore b/plugins/apps/vendor/github.com/codegangsta/inject/.gitignore deleted file mode 100644 index df3df8a90..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -inject -inject.test diff --git a/plugins/apps/vendor/github.com/codegangsta/inject/LICENSE b/plugins/apps/vendor/github.com/codegangsta/inject/LICENSE deleted file mode 100644 index eb68a0e05..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Jeremy Saenz - -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/plugins/apps/vendor/github.com/codegangsta/inject/README.md b/plugins/apps/vendor/github.com/codegangsta/inject/README.md deleted file mode 100644 index 679abe01a..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# inject --- - import "github.com/codegangsta/inject" - -Package inject provides utilities for mapping and injecting dependencies in -various ways. - -Language Translations: -* [简体中文](translations/README_zh_cn.md) - -## Usage - -#### func InterfaceOf - -```go -func InterfaceOf(value interface{}) reflect.Type -``` -InterfaceOf dereferences a pointer to an Interface type. It panics if value is -not an pointer to an interface. - -#### type Applicator - -```go -type Applicator interface { - // Maps dependencies in the Type map to each field in the struct - // that is tagged with 'inject'. Returns an error if the injection - // fails. - Apply(interface{}) error -} -``` - -Applicator represents an interface for mapping dependencies to a struct. - -#### type Injector - -```go -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent sets the parent of the injector. If the injector cannot find a - // dependency in its Type map it will check its parent before returning an - // error. - SetParent(Injector) -} -``` - -Injector represents an interface for mapping and injecting dependencies into -structs and function arguments. - -#### func New - -```go -func New() Injector -``` -New returns a new Injector. - -#### type Invoker - -```go -type Invoker interface { - // Invoke attempts to call the interface{} provided as a function, - // providing dependencies for function arguments based on Type. Returns - // a slice of reflect.Value representing the returned values of the function. - // Returns an error if the injection fails. - Invoke(interface{}) ([]reflect.Value, error) -} -``` - -Invoker represents an interface for calling functions via reflection. - -#### type TypeMapper - -```go -type TypeMapper interface { - // Maps the interface{} value based on its immediate type from reflect.TypeOf. - Map(interface{}) TypeMapper - // Maps the interface{} value based on the pointer of an Interface provided. - // This is really only useful for mapping a value as an interface, as interfaces - // cannot at this time be referenced directly without a pointer. - MapTo(interface{}, interface{}) TypeMapper - // Provides a possibility to directly insert a mapping based on type and value. - // This makes it possible to directly map type arguments not possible to instantiate - // with reflect like unidirectional channels. - Set(reflect.Type, reflect.Value) TypeMapper - // Returns the Value that is mapped to the current type. Returns a zeroed Value if - // the Type has not been mapped. - Get(reflect.Type) reflect.Value -} -``` - -TypeMapper represents an interface for mapping interface{} values based on type. diff --git a/plugins/apps/vendor/github.com/codegangsta/inject/inject.go b/plugins/apps/vendor/github.com/codegangsta/inject/inject.go deleted file mode 100644 index 3ff713c8a..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/inject.go +++ /dev/null @@ -1,187 +0,0 @@ -// Package inject provides utilities for mapping and injecting dependencies in various ways. -package inject - -import ( - "fmt" - "reflect" -) - -// Injector represents an interface for mapping and injecting dependencies into structs -// and function arguments. -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent sets the parent of the injector. If the injector cannot find a - // dependency in its Type map it will check its parent before returning an - // error. - SetParent(Injector) -} - -// Applicator represents an interface for mapping dependencies to a struct. -type Applicator interface { - // Maps dependencies in the Type map to each field in the struct - // that is tagged with 'inject'. Returns an error if the injection - // fails. - Apply(interface{}) error -} - -// Invoker represents an interface for calling functions via reflection. -type Invoker interface { - // Invoke attempts to call the interface{} provided as a function, - // providing dependencies for function arguments based on Type. Returns - // a slice of reflect.Value representing the returned values of the function. - // Returns an error if the injection fails. - Invoke(interface{}) ([]reflect.Value, error) -} - -// TypeMapper represents an interface for mapping interface{} values based on type. -type TypeMapper interface { - // Maps the interface{} value based on its immediate type from reflect.TypeOf. - Map(interface{}) TypeMapper - // Maps the interface{} value based on the pointer of an Interface provided. - // This is really only useful for mapping a value as an interface, as interfaces - // cannot at this time be referenced directly without a pointer. - MapTo(interface{}, interface{}) TypeMapper - // Provides a possibility to directly insert a mapping based on type and value. - // This makes it possible to directly map type arguments not possible to instantiate - // with reflect like unidirectional channels. - Set(reflect.Type, reflect.Value) TypeMapper - // Returns the Value that is mapped to the current type. Returns a zeroed Value if - // the Type has not been mapped. - Get(reflect.Type) reflect.Value -} - -type injector struct { - values map[reflect.Type]reflect.Value - parent Injector -} - -// InterfaceOf dereferences a pointer to an Interface type. -// It panics if value is not an pointer to an interface. -func InterfaceOf(value interface{}) reflect.Type { - t := reflect.TypeOf(value) - - for t.Kind() == reflect.Ptr { - t = t.Elem() - } - - if t.Kind() != reflect.Interface { - panic("Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)") - } - - return t -} - -// New returns a new Injector. -func New() Injector { - return &injector{ - values: make(map[reflect.Type]reflect.Value), - } -} - -// Invoke attempts to call the interface{} provided as a function, -// providing dependencies for function arguments based on Type. -// Returns a slice of reflect.Value representing the returned values of the function. -// Returns an error if the injection fails. -// It panics if f is not a function -func (inj *injector) Invoke(f interface{}) ([]reflect.Value, error) { - t := reflect.TypeOf(f) - - var in = make([]reflect.Value, t.NumIn()) //Panic if t is not kind of Func - for i := 0; i < t.NumIn(); i++ { - argType := t.In(i) - val := inj.Get(argType) - if !val.IsValid() { - return nil, fmt.Errorf("Value not found for type %v", argType) - } - - in[i] = val - } - - return reflect.ValueOf(f).Call(in), nil -} - -// Maps dependencies in the Type map to each field in the struct -// that is tagged with 'inject'. -// Returns an error if the injection fails. -func (inj *injector) Apply(val interface{}) error { - v := reflect.ValueOf(val) - - for v.Kind() == reflect.Ptr { - v = v.Elem() - } - - if v.Kind() != reflect.Struct { - return nil // Should not panic here ? - } - - t := v.Type() - - for i := 0; i < v.NumField(); i++ { - f := v.Field(i) - structField := t.Field(i) - if f.CanSet() && (structField.Tag == "inject" || structField.Tag.Get("inject") != "") { - ft := f.Type() - v := inj.Get(ft) - if !v.IsValid() { - return fmt.Errorf("Value not found for type %v", ft) - } - - f.Set(v) - } - - } - - return nil -} - -// Maps the concrete value of val to its dynamic type using reflect.TypeOf, -// It returns the TypeMapper registered in. -func (i *injector) Map(val interface{}) TypeMapper { - i.values[reflect.TypeOf(val)] = reflect.ValueOf(val) - return i -} - -func (i *injector) MapTo(val interface{}, ifacePtr interface{}) TypeMapper { - i.values[InterfaceOf(ifacePtr)] = reflect.ValueOf(val) - return i -} - -// Maps the given reflect.Type to the given reflect.Value and returns -// the Typemapper the mapping has been registered in. -func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper { - i.values[typ] = val - return i -} - -func (i *injector) Get(t reflect.Type) reflect.Value { - val := i.values[t] - - if val.IsValid() { - return val - } - - // no concrete types found, try to find implementors - // if t is an interface - if t.Kind() == reflect.Interface { - for k, v := range i.values { - if k.Implements(t) { - val = v - break - } - } - } - - // Still no type found, try to look it up on the parent - if !val.IsValid() && i.parent != nil { - val = i.parent.Get(t) - } - - return val - -} - -func (i *injector) SetParent(parent Injector) { - i.parent = parent -} diff --git a/plugins/apps/vendor/github.com/codegangsta/inject/inject_test.go b/plugins/apps/vendor/github.com/codegangsta/inject/inject_test.go deleted file mode 100644 index eb94471d3..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/inject_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package inject_test - -import ( - "fmt" - "github.com/codegangsta/inject" - "reflect" - "testing" -) - -type SpecialString interface { -} - -type TestStruct struct { - Dep1 string `inject:"t" json:"-"` - Dep2 SpecialString `inject` - Dep3 string -} - -type Greeter struct { - Name string -} - -func (g *Greeter) String() string { - return "Hello, My name is" + g.Name -} - -/* Test Helpers */ -func expect(t *testing.T, a interface{}, b interface{}) { - if a != b { - t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -} - -func refute(t *testing.T, a interface{}, b interface{}) { - if a == b { - t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -} - -func Test_InjectorInvoke(t *testing.T) { - injector := inject.New() - expect(t, injector == nil, false) - - dep := "some dependency" - injector.Map(dep) - dep2 := "another dep" - injector.MapTo(dep2, (*SpecialString)(nil)) - dep3 := make(chan *SpecialString) - dep4 := make(chan *SpecialString) - typRecv := reflect.ChanOf(reflect.RecvDir, reflect.TypeOf(dep3).Elem()) - typSend := reflect.ChanOf(reflect.SendDir, reflect.TypeOf(dep4).Elem()) - injector.Set(typRecv, reflect.ValueOf(dep3)) - injector.Set(typSend, reflect.ValueOf(dep4)) - - _, err := injector.Invoke(func(d1 string, d2 SpecialString, d3 <-chan *SpecialString, d4 chan<- *SpecialString) { - expect(t, d1, dep) - expect(t, d2, dep2) - expect(t, reflect.TypeOf(d3).Elem(), reflect.TypeOf(dep3).Elem()) - expect(t, reflect.TypeOf(d4).Elem(), reflect.TypeOf(dep4).Elem()) - expect(t, reflect.TypeOf(d3).ChanDir(), reflect.RecvDir) - expect(t, reflect.TypeOf(d4).ChanDir(), reflect.SendDir) - }) - - expect(t, err, nil) -} - -func Test_InjectorInvokeReturnValues(t *testing.T) { - injector := inject.New() - expect(t, injector == nil, false) - - dep := "some dependency" - injector.Map(dep) - dep2 := "another dep" - injector.MapTo(dep2, (*SpecialString)(nil)) - - result, err := injector.Invoke(func(d1 string, d2 SpecialString) string { - expect(t, d1, dep) - expect(t, d2, dep2) - return "Hello world" - }) - - expect(t, result[0].String(), "Hello world") - expect(t, err, nil) -} - -func Test_InjectorApply(t *testing.T) { - injector := inject.New() - - injector.Map("a dep").MapTo("another dep", (*SpecialString)(nil)) - - s := TestStruct{} - err := injector.Apply(&s) - expect(t, err, nil) - - expect(t, s.Dep1, "a dep") - expect(t, s.Dep2, "another dep") - expect(t, s.Dep3, "") -} - -func Test_InterfaceOf(t *testing.T) { - iType := inject.InterfaceOf((*SpecialString)(nil)) - expect(t, iType.Kind(), reflect.Interface) - - iType = inject.InterfaceOf((**SpecialString)(nil)) - expect(t, iType.Kind(), reflect.Interface) - - // Expecting nil - defer func() { - rec := recover() - refute(t, rec, nil) - }() - iType = inject.InterfaceOf((*testing.T)(nil)) -} - -func Test_InjectorSet(t *testing.T) { - injector := inject.New() - typ := reflect.TypeOf("string") - typSend := reflect.ChanOf(reflect.SendDir, typ) - typRecv := reflect.ChanOf(reflect.RecvDir, typ) - - // instantiating unidirectional channels is not possible using reflect - // http://golang.org/src/pkg/reflect/value.go?s=60463:60504#L2064 - chanRecv := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, typ), 0) - chanSend := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, typ), 0) - - injector.Set(typSend, chanSend) - injector.Set(typRecv, chanRecv) - - expect(t, injector.Get(typSend).IsValid(), true) - expect(t, injector.Get(typRecv).IsValid(), true) - expect(t, injector.Get(chanSend.Type()).IsValid(), false) -} - -func Test_InjectorGet(t *testing.T) { - injector := inject.New() - - injector.Map("some dependency") - - expect(t, injector.Get(reflect.TypeOf("string")).IsValid(), true) - expect(t, injector.Get(reflect.TypeOf(11)).IsValid(), false) -} - -func Test_InjectorSetParent(t *testing.T) { - injector := inject.New() - injector.MapTo("another dep", (*SpecialString)(nil)) - - injector2 := inject.New() - injector2.SetParent(injector) - - expect(t, injector2.Get(inject.InterfaceOf((*SpecialString)(nil))).IsValid(), true) -} - -func TestInjectImplementors(t *testing.T) { - injector := inject.New() - g := &Greeter{"Jeremy"} - injector.Map(g) - - expect(t, injector.Get(inject.InterfaceOf((*fmt.Stringer)(nil))).IsValid(), true) -} diff --git a/plugins/apps/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md b/plugins/apps/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md deleted file mode 100644 index 0ac3d3f55..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md +++ /dev/null @@ -1,85 +0,0 @@ -# inject --- - import "github.com/codegangsta/inject" - -inject包提供了多种对实体的映射和依赖注入方式。 - -## 用法 - -#### func InterfaceOf - -```go -func InterfaceOf(value interface{}) reflect.Type -``` -函数InterfaceOf返回指向接口类型的指针。如果传入的value值不是指向接口的指针,将抛出一个panic异常。 - -#### type Applicator - -```go -type Applicator interface { - // 在Type map中维持对结构体中每个域的引用并用'inject'来标记 - // 如果注入失败将会返回一个error. - Apply(interface{}) error -} -``` - -Applicator接口表示到结构体的依赖映射关系。 - -#### type Injector - -```go -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent用来设置父injector. 如果在当前injector的Type map中找不到依赖, - // 将会继续从它的父injector中找,直到返回error. - SetParent(Injector) -} -``` - -Injector接口表示对结构体、函数参数的映射和依赖注入。 - -#### func New - -```go -func New() Injector -``` -New创建并返回一个Injector. - -#### type Invoker - -```go -type Invoker interface { - // Invoke尝试将interface{}作为一个函数来调用,并基于Type为函数提供参数。 - // 它将返回reflect.Value的切片,其中存放原函数的返回值。 - // 如果注入失败则返回error. - Invoke(interface{}) ([]reflect.Value, error) -} -``` - -Invoker接口表示通过反射进行函数调用。 - -#### type TypeMapper - -```go -type TypeMapper interface { - // 基于调用reflect.TypeOf得到的类型映射interface{}的值。 - Map(interface{}) TypeMapper - // 基于提供的接口的指针映射interface{}的值。 - // 该函数仅用来将一个值映射为接口,因为接口无法不通过指针而直接引用到。 - MapTo(interface{}, interface{}) TypeMapper - // 为直接插入基于类型和值的map提供一种可能性。 - // 它使得这一类直接映射成为可能:无法通过反射直接实例化的类型参数,如单向管道。 - Set(reflect.Type, reflect.Value) TypeMapper - // 返回映射到当前类型的Value. 如果Type没被映射,将返回对应的零值。 - Get(reflect.Type) reflect.Value -} -``` - -TypeMapper接口用来表示基于类型到接口值的映射。 - - -## 译者 - -张强 (qqbunny@yeah.net) \ No newline at end of file diff --git a/plugins/apps/vendor/github.com/codegangsta/inject/update_readme.sh b/plugins/apps/vendor/github.com/codegangsta/inject/update_readme.sh deleted file mode 100644 index 3cb21111c..000000000 --- a/plugins/apps/vendor/github.com/codegangsta/inject/update_readme.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -go get github.com/robertkrimen/godocdown/godocdown -godocdown >README.md diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/LICENSE b/plugins/apps/vendor/github.com/codeskyblue/go-sh/LICENSE deleted file mode 100644 index e06d20818..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/OLD_README.md b/plugins/apps/vendor/github.com/codeskyblue/go-sh/OLD_README.md deleted file mode 100644 index 7e899402d..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/OLD_README.md +++ /dev/null @@ -1,69 +0,0 @@ -## OLD README -First give you a full example, I will explain every command below. - - session := sh.NewSession() - session.Env["PATH"] = "/usr/bin:/bin" - session.Stdout = os.Stdout - session.Stderr = os.Stderr - session.Alias("ll", "ls", "-l") - session.ShowCMD = true // enable for debug - var err error - err = session.Call("ll", "/") - if err != nil { - log.Fatal(err) - } - ret, err := session.Capture("pwd", sh.Dir("/home")) # wraper of session.Call - if err != nil { - log.Fatal(err) - } - # ret is "/home\n" - fmt.Println(ret) - -create a new Session - - session := sh.NewSession() - -use alias like this - - session.Alias("ll", "ls", "-l") # like alias ll='ls -l' - -set current env like this - - session.Env["BUILD_ID"] = "123" # like export BUILD_ID=123 - -set current directory - - session.Set(sh.Dir("/")) # like cd / - -pipe is also supported - - session.Command("echo", "hello\tworld").Command("cut", "-f2") - // output should be "world" - session.Run() - -test, the build in command support - - session.Test("d", "dir") // test dir - session.Test("f", "file) // test regular file - -with `Alias Env Set Call Capture Command` a shell scripts can be easily converted into golang program. below is a shell script. - - #!/bin/bash - - # - export PATH=/usr/bin:/bin - alias ll='ls -l' - cd /usr - if test -d "local" - then - ll local | awk '{print $1, $NF}' - fi - -convert to golang, will be - - s := sh.NewSession() - s.Env["PATH"] = "/usr/bin:/bin" - s.Set(sh.Dir("/usr")) - s.Alias("ll", "ls", "-l") - if s.Test("d", "local") { - s.Command("ll", "local").Command("awk", "{print $1, $NF}").Run() - } diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/README.md b/plugins/apps/vendor/github.com/codeskyblue/go-sh/README.md deleted file mode 100644 index 28614708d..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/README.md +++ /dev/null @@ -1,85 +0,0 @@ -## go-sh -[![wercker status](https://app.wercker.com/status/009acbd4f00ccc6de7e2554e12a50d84/s "wercker status")](https://app.wercker.com/project/bykey/009acbd4f00ccc6de7e2554e12a50d84) -[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/codeskyblue/go-sh) - -*If you depend on the old api, see tag: v.0.1* - -install: `go get github.com/codeskyblue/go-sh` - -Pipe Example: - - package main - - import "github.com/codeskyblue/go-sh" - - func main() { - sh.Command("echo", "hello\tworld").Command("cut", "-f2").Run() - } - -Because I like os/exec, `go-sh` is very much modelled after it. However, `go-sh` provides a better experience. - -These are some of its features: - -* keep the variable environment (e.g. export) -* alias support (e.g. alias in shell) -* remember current dir -* pipe command -* shell build-in commands echo & test -* timeout support - -Examples are important: - - sh: echo hello - go: sh.Command("echo", "hello").Run() - - sh: export BUILD_ID=123 - go: s = sh.NewSession().SetEnv("BUILD_ID", "123") - - sh: alias ll='ls -l' - go: s = sh.NewSession().Alias('ll', 'ls', '-l') - - sh: (cd /; pwd) - go: sh.Command("pwd", sh.Dir("/")).Run() - - sh: test -d data || mkdir data - go: if ! sh.Test("dir", "data") { sh.Command("mkdir", "data").Run() } - - sh: cat first second | awk '{print $1}' - go: sh.Command("cat", "first", "second").Command("awk", "{print $1}").Run() - - sh: count=$(echo "one two three" | wc -w) - go: count, err := sh.Echo("one two three").Command("wc", "-w").Output() - - sh(in ubuntu): timeout 1s sleep 3 - go: c := sh.Command("sleep", "3"); c.Start(); c.WaitTimeout(time.Second) # default SIGKILL - go: out, err := sh.Command("sleep", "3").SetTimeout(time.Second).Output() # set session timeout and get output) - - sh: echo hello | cat - go: out, err := sh.Command("cat").SetInput("hello").Output() - - sh: cat # read from stdin - go: out, err := sh.Command("cat").SetStdin(os.Stdin).Output() - -If you need to keep env and dir, it is better to create a session - - session := sh.NewSession() - session.SetEnv("BUILD_ID", "123") - session.SetDir("/") - # then call cmd - session.Command("echo", "hello").Run() - # set ShowCMD to true for easily debug - session.ShowCMD = true - -for more information, it better to see docs. -[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/codeskyblue/go-sh) - -### contribute -If you love this project, starring it will encourage the coder. Pull requests are welcome. - -support the author: [alipay](https://me.alipay.com/goskyblue) - -### thanks -this project is based on . thanks for the author. - -# the reason to use Go shell -Sometimes we need to write shell scripts, but shell scripts are not good at working cross platform, Go, on the other hand, is good at that. Is there a good way to use Go to write shell like scripts? Using go-sh we can do this now. diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/example1.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/example1.go deleted file mode 100644 index cdc7f6c39..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/example1.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "github.com/codeskyblue/go-sh" -) - -func main() { - sh.Command("echo", "hello").Run() - out, err := sh.Command("echo", "hello").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println("output is", string(out)) - - var a int - sh.Command("echo", "2").UnmarshalJSON(&a) - fmt.Println("a =", a) - - s := sh.NewSession() - s.Alias("hi", "echo", "hi") - s.Command("hi", "boy").Run() - - fmt.Print("pwd = ") - s.Command("pwd", sh.Dir("/")).Run() - - if !sh.Test("dir", "data") { - sh.Command("echo", "mkdir", "data").Run() - } - - sh.Command("echo", "hello", "world"). - Command("awk", `{print "second arg is "$2}`).Run() - s.ShowCMD = true - s.Command("echo", "hello", "world"). - Command("awk", `{print "second arg is "$2}`).Run() - - s.SetEnv("BUILD_ID", "123").Command("bash", "-c", "echo $BUILD_ID").Run() - s.Command("bash", "-c", "echo current shell is $SHELL").Run() -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/less/less.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/less/less.go deleted file mode 100644 index ffced2e81..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/less/less.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/codeskyblue/go-sh" - -func main() { - sh.Command("less", "less.go").Run() -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go deleted file mode 100644 index b7ecd3bed..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "flag" - "fmt" - - "github.com/codeskyblue/go-sh" -) - -func main() { - flag.Parse() - if flag.NArg() != 1 { - fmt.Println("Usage: PROGRAM ") - return - } - sh.Command("tail", "-f", flag.Arg(0)).Run() -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go deleted file mode 100644 index 852908a47..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "fmt" - "time" - - sh "github.com/codeskyblue/go-sh" -) - -func main() { - c := sh.Command("sleep", "3") - c.Start() - err := c.WaitTimeout(time.Second * 1) - if err != nil { - fmt.Printf("timeout should happend: %v\n", err) - } - // timeout should be a session - out, err := sh.Command("sleep", "2").SetTimeout(time.Second).Output() - fmt.Printf("output:(%s), err(%v)\n", string(out), err) - - out, err = sh.Command("echo", "hello").SetTimeout(time.Second).Output() - fmt.Printf("output:(%s), err(%v)\n", string(out), err) -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example_test.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/example_test.go deleted file mode 100644 index 5abfed64d..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/example_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package sh_test - -import ( - "fmt" - - "github.com/codeskyblue/go-sh" -) - -func ExampleCommand() { - out, err := sh.Command("echo", "hello").Output() - fmt.Println(string(out), err) -} - -func ExampleCommandPipe() { - out, err := sh.Command("echo", "-n", "hi").Command("wc", "-c").Output() - fmt.Println(string(out), err) -} - -func ExampleCommandSetDir() { - out, err := sh.Command("pwd", sh.Dir("/")).Output() - fmt.Println(string(out), err) -} - -func ExampleTest() { - if sh.Test("dir", "mydir") { - fmt.Println("mydir exists") - } -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/pipe.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/pipe.go deleted file mode 100644 index c35f4e2a0..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/pipe.go +++ /dev/null @@ -1,148 +0,0 @@ -package sh - -import ( - "bytes" - "encoding/json" - "encoding/xml" - "errors" - "io" - "os" - "strings" - "syscall" - "time" -) - -var ErrExecTimeout = errors.New("execute timeout") - -// unmarshal shell output to decode json -func (s *Session) UnmarshalJSON(data interface{}) (err error) { - bufrw := bytes.NewBuffer(nil) - s.Stdout = bufrw - if err = s.Run(); err != nil { - return - } - return json.NewDecoder(bufrw).Decode(data) -} - -// unmarshal command output into xml -func (s *Session) UnmarshalXML(data interface{}) (err error) { - bufrw := bytes.NewBuffer(nil) - s.Stdout = bufrw - if err = s.Run(); err != nil { - return - } - return xml.NewDecoder(bufrw).Decode(data) -} - -// start command -func (s *Session) Start() (err error) { - s.started = true - var rd *io.PipeReader - var wr *io.PipeWriter - var length = len(s.cmds) - if s.ShowCMD { - var cmds = make([]string, 0, 4) - for _, cmd := range s.cmds { - cmds = append(cmds, strings.Join(cmd.Args, " ")) - } - s.writePrompt(strings.Join(cmds, " | ")) - } - for index, cmd := range s.cmds { - if index == 0 { - cmd.Stdin = s.Stdin - } else { - cmd.Stdin = rd - } - if index != length { - rd, wr = io.Pipe() // create pipe - cmd.Stdout = wr - cmd.Stderr = os.Stderr - } - if index == length-1 { - cmd.Stdout = s.Stdout - cmd.Stderr = s.Stderr - } - err = cmd.Start() - if err != nil { - return - } - } - return -} - -// Should be call after Start() -// only catch the last command error -func (s *Session) Wait() (err error) { - for _, cmd := range s.cmds { - err = cmd.Wait() - wr, ok := cmd.Stdout.(*io.PipeWriter) - if ok { - wr.Close() - } - } - return err -} - -func (s *Session) Kill(sig os.Signal) { - for _, cmd := range s.cmds { - if cmd.Process != nil { - cmd.Process.Signal(sig) - } - } -} - -func (s *Session) WaitTimeout(timeout time.Duration) (err error) { - select { - case <-time.After(timeout): - s.Kill(syscall.SIGKILL) - return ErrExecTimeout - case err = <-Go(s.Wait): - return err - } -} - -func Go(f func() error) chan error { - ch := make(chan error) - go func() { - ch <- f() - }() - return ch -} - -func (s *Session) Run() (err error) { - if err = s.Start(); err != nil { - return - } - if s.timeout != time.Duration(0) { - return s.WaitTimeout(s.timeout) - } - return s.Wait() -} - -func (s *Session) Output() (out []byte, err error) { - oldout := s.Stdout - defer func() { - s.Stdout = oldout - }() - stdout := bytes.NewBuffer(nil) - s.Stdout = stdout - err = s.Run() - out = stdout.Bytes() - return -} - -func (s *Session) CombinedOutput() (out []byte, err error) { - oldout := s.Stdout - olderr := s.Stderr - defer func() { - s.Stdout = oldout - s.Stderr = olderr - }() - stdout := bytes.NewBuffer(nil) - s.Stdout = stdout - s.Stderr = stdout - - err = s.Run() - out = stdout.Bytes() - return -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/pipe_test.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/pipe_test.go deleted file mode 100644 index 8d0e22c0c..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/pipe_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package sh - -import ( - "encoding/xml" - "io" - "os" - "os/exec" - "strings" - "testing" - "time" -) - -func TestUnmarshalJSON(t *testing.T) { - var a int - s := NewSession() - s.ShowCMD = true - err := s.Command("echo", []string{"1"}).UnmarshalJSON(&a) - if err != nil { - t.Error(err) - } - if a != 1 { - t.Errorf("expect a tobe 1, but got %d", a) - } -} - -func TestUnmarshalXML(t *testing.T) { - s := NewSession() - xmlSample := ` -` - type server struct { - XMLName xml.Name `xml:"server"` - Version string `xml:"version,attr"` - } - data := &server{} - s.Command("echo", xmlSample).UnmarshalXML(data) - if data.Version != "1" { - t.Error(data) - } -} - -func TestPipe(t *testing.T) { - s := NewSession() - s.ShowCMD = true - s.Call("echo", "hello") - err := s.Command("echo", "hi").Command("cat", "-n").Start() - if err != nil { - t.Error(err) - } - err = s.Wait() - if err != nil { - t.Error(err) - } - out, err := s.Command("echo", []string{"hello"}).Output() - if err != nil { - t.Error(err) - } - if string(out) != "hello\n" { - t.Error("capture wrong output:", out) - } - s.Command("echo", []string{"hello\tworld"}).Command("cut", []string{"-f2"}).Run() -} - -func TestPipeCommand(t *testing.T) { - c1 := exec.Command("echo", "good") - rd, wr := io.Pipe() - c1.Stdout = wr - c2 := exec.Command("cat", "-n") - c2.Stdout = os.Stdout - c2.Stdin = rd - c1.Start() - c2.Start() - - c1.Wait() - wc, ok := c1.Stdout.(io.WriteCloser) - if ok { - wc.Close() - } - c2.Wait() -} - -func TestPipeInput(t *testing.T) { - s := NewSession() - s.ShowCMD = true - s.SetInput("first line\nsecond line\n") - out, err := s.Command("grep", "second").Output() - if err != nil { - t.Error(err) - } - if string(out) != "second line\n" { - t.Error("capture wrong output:", out) - } -} - -func TestTimeout(t *testing.T) { - s := NewSession() - err := s.Command("sleep", "2").Start() - if err != nil { - t.Fatal(err) - } - err = s.WaitTimeout(time.Second) - if err != ErrExecTimeout { - t.Fatal(err) - } -} - -func TestSetTimeout(t *testing.T) { - s := NewSession() - s.SetTimeout(time.Second) - defer s.SetTimeout(0) - err := s.Command("sleep", "2").Run() - if err != ErrExecTimeout { - t.Fatal(err) - } -} - -func TestCombinedOutput(t *testing.T) { - s := NewSession() - bytes, err := s.Command("sh", "-c", "echo stderr >&2 ; echo stdout").CombinedOutput() - if err != nil { - t.Error(err) - } - stringOutput := string(bytes) - if !(strings.Contains(stringOutput, "stdout") && strings.Contains(stringOutput, "stderr")) { - t.Errorf("expect output from both output streams, got '%s'", strings.TrimSpace(stringOutput)) - } -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/sh.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/sh.go deleted file mode 100644 index 15f1b85d5..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/sh.go +++ /dev/null @@ -1,200 +0,0 @@ -/* -Package go-sh is intented to make shell call with golang more easily. -Some usage is more similar to os/exec, eg: Run(), Output(), Command(name, args...) - -But with these similar function, pipe is added in and this package also got shell-session support. - -Why I love golang so much, because the usage of golang is simple, but the power is unlimited. I want to make this pakcage got the sample style like golang. - - // just like os/exec - sh.Command("echo", "hello").Run() - - // support pipe - sh.Command("echo", "hello").Command("wc", "-c").Run() - - // create a session to store dir and env - sh.NewSession().SetDir("/").Command("pwd") - - // shell buildin command - "test" - sh.Test("dir", "mydir") - - // like shell call: (cd /; pwd) - sh.Command("pwd", sh.Dir("/")) same with sh.Command(sh.Dir("/"), "pwd") - - // output to json and xml easily - v := map[string] int {} - err = sh.Command("echo", `{"number": 1}`).UnmarshalJSON(&v) -*/ -package sh - -import ( - "fmt" - "io" - "os" - "os/exec" - "reflect" - "strings" - "time" - - "github.com/codegangsta/inject" -) - -type Dir string - -type Session struct { - inj inject.Injector - alias map[string][]string - cmds []*exec.Cmd - dir Dir - started bool - Env map[string]string - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer - ShowCMD bool // enable for debug - timeout time.Duration -} - -func (s *Session) writePrompt(args ...interface{}) { - var ps1 = fmt.Sprintf("[golang-sh]$") - args = append([]interface{}{ps1}, args...) - fmt.Fprintln(s.Stderr, args...) -} - -func NewSession() *Session { - env := make(map[string]string) - for _, key := range []string{"PATH"} { - env[key] = os.Getenv(key) - } - s := &Session{ - inj: inject.New(), - alias: make(map[string][]string), - dir: Dir(""), - Stdin: strings.NewReader(""), - Stdout: os.Stdout, - Stderr: os.Stderr, - Env: env, - } - return s -} - -func InteractiveSession() *Session { - s := NewSession() - s.SetStdin(os.Stdin) - return s -} - -func Command(name string, a ...interface{}) *Session { - s := NewSession() - return s.Command(name, a...) -} - -func Echo(in string) *Session { - s := NewSession() - return s.SetInput(in) -} - -func (s *Session) Alias(alias, cmd string, args ...string) { - v := []string{cmd} - v = append(v, args...) - s.alias[alias] = v -} - -func (s *Session) Command(name string, a ...interface{}) *Session { - var args = make([]string, 0) - var sType = reflect.TypeOf("") - - // init cmd, args, dir, envs - // if not init, program may panic - s.inj.Map(name).Map(args).Map(s.dir).Map(map[string]string{}) - for _, v := range a { - switch reflect.TypeOf(v) { - case sType: - args = append(args, v.(string)) - default: - s.inj.Map(v) - } - } - if len(args) != 0 { - s.inj.Map(args) - } - s.inj.Invoke(s.appendCmd) - return s -} - -// combine Command and Run -func (s *Session) Call(name string, a ...interface{}) error { - return s.Command(name, a...).Run() -} - -/* -func (s *Session) Exec(cmd string, args ...string) error { - return s.Call(cmd, args) -} -*/ - -func (s *Session) SetEnv(key, value string) *Session { - s.Env[key] = value - return s -} - -func (s *Session) SetDir(dir string) *Session { - s.dir = Dir(dir) - return s -} - -func (s *Session) SetInput(in string) *Session { - s.Stdin = strings.NewReader(in) - return s -} - -func (s *Session) SetStdin(r io.Reader) *Session { - s.Stdin = r - return s -} - -func (s *Session) SetTimeout(d time.Duration) *Session { - s.timeout = d - return s -} - -func newEnviron(env map[string]string, inherit bool) []string { //map[string]string { - environ := make([]string, 0, len(env)) - if inherit { - for _, line := range os.Environ() { - for k, _ := range env { - if strings.HasPrefix(line, k+"=") { - goto CONTINUE - } - } - environ = append(environ, line) - CONTINUE: - } - } - for k, v := range env { - environ = append(environ, k+"="+v) - } - return environ -} - -func (s *Session) appendCmd(cmd string, args []string, cwd Dir, env map[string]string) { - if s.started { - s.started = false - s.cmds = make([]*exec.Cmd, 0) - } - for k, v := range s.Env { - if _, ok := env[k]; !ok { - env[k] = v - } - } - environ := newEnviron(s.Env, true) // true: inherit sys-env - v, ok := s.alias[cmd] - if ok { - cmd = v[0] - args = append(v[1:], args...) - } - c := exec.Command(cmd, args...) - c.Env = environ - c.Dir = string(cwd) - s.cmds = append(s.cmds, c) -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/sh_test.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/sh_test.go deleted file mode 100644 index be5c27998..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/sh_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package sh - -import ( - "fmt" - "log" - "runtime" - "strings" - "testing" -) - -func TestAlias(t *testing.T) { - s := NewSession() - s.Alias("gr", "echo", "hi") - out, err := s.Command("gr", "sky").Output() - if err != nil { - t.Error(err) - } - if string(out) != "hi sky\n" { - t.Errorf("expect 'hi sky' but got:%s", string(out)) - } -} - -func ExampleSession_Command() { - s := NewSession() - out, err := s.Command("echo", "hello").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: hello -} - -func ExampleSession_Command_pipe() { - s := NewSession() - out, err := s.Command("echo", "hello", "world").Command("awk", "{print $2}").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: world -} - -func ExampleSession_Alias() { - s := NewSession() - s.Alias("alias_echo_hello", "echo", "hello") - out, err := s.Command("alias_echo_hello", "world").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: hello world -} - -func TestEcho(t *testing.T) { - out, err := Echo("one two three").Command("wc", "-w").Output() - if err != nil { - t.Error(err) - } - if strings.TrimSpace(string(out)) != "3" { - t.Errorf("expect '3' but got:%s", string(out)) - } -} - -func TestSession(t *testing.T) { - if runtime.GOOS == "windows" { - t.Log("ignore test on windows") - return - } - session := NewSession() - session.ShowCMD = true - err := session.Call("pwd") - if err != nil { - t.Error(err) - } - out, err := session.SetDir("/").Command("pwd").Output() - if err != nil { - t.Error(err) - } - if string(out) != "/\n" { - t.Errorf("expect /, but got %s", string(out)) - } -} - -/* - #!/bin/bash - - # - export PATH=/usr/bin:/bin - alias ll='ls -l' - cd /usr - if test -d "local" - then - ll local | awk '{print $1, $NF}' | grep bin - fi -*/ -func Example(t *testing.T) { - s := NewSession() - //s.ShowCMD = true - s.Env["PATH"] = "/usr/bin:/bin" - s.SetDir("/bin") - s.Alias("ll", "ls", "-l") - - if s.Test("d", "local") { - //s.Command("ll", []string{"local"}).Command("awk", []string{"{print $1, $NF}"}).Command("grep", []string{"bin"}).Run() - s.Command("ll", "local").Command("awk", "{print $1, $NF}").Command("grep", "bin").Run() - } -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/test.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/test.go deleted file mode 100644 index b9d310527..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/test.go +++ /dev/null @@ -1,64 +0,0 @@ -package sh - -import ( - "os" - "path/filepath" -) - -func filetest(name string, modemask os.FileMode) (match bool, err error) { - fi, err := os.Stat(name) - if err != nil { - return - } - match = (fi.Mode() & modemask) == modemask - return -} - -func (s *Session) pwd() string { - dir := string(s.dir) - if dir == "" { - dir, _ = os.Getwd() - } - return dir -} - -func (s *Session) abspath(name string) string { - if filepath.IsAbs(name) { - return name - } - return filepath.Join(s.pwd(), name) -} - -func init() { - //log.SetFlags(log.Lshortfile | log.LstdFlags) -} - -// expression can be dir, file, link -func (s *Session) Test(expression string, argument string) bool { - var err error - var fi os.FileInfo - fi, err = os.Lstat(s.abspath(argument)) - switch expression { - case "d", "dir": - return err == nil && fi.IsDir() - case "f", "file": - return err == nil && fi.Mode().IsRegular() - case "x", "executable": - /* - fmt.Println(expression, argument) - if err == nil { - fmt.Println(fi.Mode()) - } - */ - return err == nil && fi.Mode()&os.FileMode(0100) != 0 - case "L", "link": - return err == nil && fi.Mode()&os.ModeSymlink != 0 - } - return false -} - -// expression can be d,dir, f,file, link -func Test(exp string, arg string) bool { - s := NewSession() - return s.Test(exp, arg) -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/test_test.go b/plugins/apps/vendor/github.com/codeskyblue/go-sh/test_test.go deleted file mode 100644 index 15225aa9a..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/test_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package sh_test - -import ( - "testing" - - "github.com/codeskyblue/go-sh" -) - -var s = sh.NewSession() - -type T struct{ *testing.T } - -func NewT(t *testing.T) *T { - return &T{t} -} - -func (t *T) checkTest(exp string, arg string, result bool) { - r := s.Test(exp, arg) - if r != result { - t.Errorf("test -%s %s, %v != %v", exp, arg, r, result) - } -} - -func TestTest(i *testing.T) { - t := NewT(i) - t.checkTest("d", "../go-sh", true) - t.checkTest("d", "./yymm", false) - - // file test - t.checkTest("f", "testdata/hello.txt", true) - t.checkTest("f", "testdata/xxxxx", false) - t.checkTest("f", "testdata/yymm", false) - - // link test - t.checkTest("link", "testdata/linkfile", true) - t.checkTest("link", "testdata/xxxxxlinkfile", false) - t.checkTest("link", "testdata/hello.txt", false) - - // executable test - t.checkTest("x", "testdata/executable", true) - t.checkTest("x", "testdata/xxxxx", false) - t.checkTest("x", "testdata/hello.txt", false) -} - -func ExampleShellTest(t *testing.T) { - // test -L - sh.Test("link", "testdata/linkfile") - sh.Test("L", "testdata/linkfile") - // test -f - sh.Test("file", "testdata/file") - sh.Test("f", "testdata/file") - // test -x - sh.Test("executable", "testdata/binfile") - sh.Test("x", "testdata/binfile") - // test -d - sh.Test("dir", "testdata/dir") - sh.Test("d", "testdata/dir") -} diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/testdata/executable b/plugins/apps/vendor/github.com/codeskyblue/go-sh/testdata/executable deleted file mode 100755 index e69de29bb..000000000 diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/testdata/hello.txt b/plugins/apps/vendor/github.com/codeskyblue/go-sh/testdata/hello.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/testdata/linkfile b/plugins/apps/vendor/github.com/codeskyblue/go-sh/testdata/linkfile deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/apps/vendor/github.com/codeskyblue/go-sh/wercker.yml b/plugins/apps/vendor/github.com/codeskyblue/go-sh/wercker.yml deleted file mode 100644 index 72c47020f..000000000 --- a/plugins/apps/vendor/github.com/codeskyblue/go-sh/wercker.yml +++ /dev/null @@ -1,28 +0,0 @@ -box: wercker/golang -# Build definition -build: - # The steps that will be executed on build - steps: - # Sets the go workspace and places you package - # at the right place in the workspace tree - - setup-go-workspace - - # Gets the dependencies - - script: - name: go get - code: | - cd $WERCKER_SOURCE_DIR - go version - go get -t . - - # Build the project - - script: - name: go build - code: | - go build . - - # Test the project - - script: - name: go test - code: | - go test -v ./... diff --git a/plugins/apps/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/apps/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/apps/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/apps/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/apps/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/apps/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/apps/vendor/github.com/ryanuber/columnize/README.md b/plugins/apps/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/apps/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/apps/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/apps/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/apps/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/apps/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/apps/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/apps/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/buildpacks/glide.yaml b/plugins/buildpacks/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/buildpacks/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/buildpacks/go.mod b/plugins/buildpacks/go.mod new file mode 100644 index 000000000..b77ee8b6f --- /dev/null +++ b/plugins/buildpacks/go.mod @@ -0,0 +1,11 @@ +module github.com/dokku/dokku/plugins/buildpacks + +go 1.14 + +require ( + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 // indirect + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 +) + +replace github.com/dokku/dokku/plugins/common => ../common diff --git a/plugins/buildpacks/go.sum b/plugins/buildpacks/go.sum new file mode 100644 index 000000000..6f9bd8d8d --- /dev/null +++ b/plugins/buildpacks/go.sum @@ -0,0 +1,45 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/buildpacks/src/commands/commands.go b/plugins/buildpacks/src/commands/commands.go index e4a6547c9..5d9cfac57 100644 --- a/plugins/buildpacks/src/commands/commands.go +++ b/plugins/buildpacks/src/commands/commands.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - columnize "github.com/ryanuber/columnize" ) const ( @@ -57,11 +56,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/buildpacks/src/glide.lock b/plugins/buildpacks/src/glide.lock deleted file mode 100644 index fe4a98f07..000000000 --- a/plugins/buildpacks/src/glide.lock +++ /dev/null @@ -1,6 +0,0 @@ -hash: 1ddab5de41d1514c2722bd7e24758ad4b60bf6956eb5b9b925fa071a1427f149 -updated: 2017-01-03T17:16:50.97156327-08:00 -imports: -- name: github.com/ryanuber/columnize - version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360 -testImports: [] diff --git a/plugins/buildpacks/src/glide.yaml b/plugins/buildpacks/src/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/buildpacks/src/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/README.md b/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/buildpacks/src/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/buildpacks/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/buildpacks/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/buildpacks/vendor/github.com/ryanuber/columnize/README.md b/plugins/buildpacks/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/buildpacks/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/buildpacks/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/buildpacks/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/common/common.go b/plugins/common/common.go index f8d5ce8c1..b34cee5bc 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -16,6 +16,7 @@ import ( "unicode" sh "github.com/codeskyblue/go-sh" + columnize "github.com/ryanuber/columnize" ) type errfunc func() error @@ -100,6 +101,17 @@ func AskForDestructiveConfirmation(name string, objectType string) error { return nil } +// CommandUsage outputs help for a command +func CommandUsage(helpHeader string, helpContent string) { + config := columnize.DefaultConfig() + config.Delim = "," + config.Prefix = " " + config.Empty = "" + content := strings.Split(helpContent, "\n")[1:] + fmt.Println(helpHeader) + fmt.Println(columnize.Format(content, config)) +} + // DockerCleanup cleans up all exited/dead containers and removes all dangling images func DockerCleanup(appName string, forceCleanup bool) error { if !forceCleanup { diff --git a/plugins/common/glide.lock b/plugins/common/glide.lock deleted file mode 100644 index 4f5cbc783..000000000 --- a/plugins/common/glide.lock +++ /dev/null @@ -1,8 +0,0 @@ -hash: e438ca8cf1bdca3e9c984bb1ee70c0d58be9da52cbe13a079a7c6cbc14210a37 -updated: 2017-01-03T17:17:27.973373328-08:00 -imports: -- name: github.com/codegangsta/inject - version: 33e0aa1cb7c019ccc3fbe049a8262a6403d30504 -- name: github.com/codeskyblue/go-sh - version: ceb46ec4630a726eeed51d0a70066c9e1102c48f -testImports: [] diff --git a/plugins/common/glide.yaml b/plugins/common/glide.yaml deleted file mode 100644 index 2d8bf9366..000000000 --- a/plugins/common/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/codeskyblue/go-sh diff --git a/plugins/common/go.mod b/plugins/common/go.mod new file mode 100644 index 000000000..0e073b4f2 --- /dev/null +++ b/plugins/common/go.mod @@ -0,0 +1,10 @@ +module github.com/dokku/dokku/plugins/common + +go 1.14 + +require ( + github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 + github.com/onsi/gomega v1.10.1 + github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 +) diff --git a/plugins/common/go.sum b/plugins/common/go.sum new file mode 100644 index 000000000..1149fa05e --- /dev/null +++ b/plugins/common/go.sum @@ -0,0 +1,50 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/common/vendor/github.com/codegangsta/inject/.gitignore b/plugins/common/vendor/github.com/codegangsta/inject/.gitignore deleted file mode 100644 index df3df8a90..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -inject -inject.test diff --git a/plugins/common/vendor/github.com/codegangsta/inject/LICENSE b/plugins/common/vendor/github.com/codegangsta/inject/LICENSE deleted file mode 100644 index eb68a0e05..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Jeremy Saenz - -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/plugins/common/vendor/github.com/codegangsta/inject/README.md b/plugins/common/vendor/github.com/codegangsta/inject/README.md deleted file mode 100644 index 679abe01a..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# inject --- - import "github.com/codegangsta/inject" - -Package inject provides utilities for mapping and injecting dependencies in -various ways. - -Language Translations: -* [简体中文](translations/README_zh_cn.md) - -## Usage - -#### func InterfaceOf - -```go -func InterfaceOf(value interface{}) reflect.Type -``` -InterfaceOf dereferences a pointer to an Interface type. It panics if value is -not an pointer to an interface. - -#### type Applicator - -```go -type Applicator interface { - // Maps dependencies in the Type map to each field in the struct - // that is tagged with 'inject'. Returns an error if the injection - // fails. - Apply(interface{}) error -} -``` - -Applicator represents an interface for mapping dependencies to a struct. - -#### type Injector - -```go -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent sets the parent of the injector. If the injector cannot find a - // dependency in its Type map it will check its parent before returning an - // error. - SetParent(Injector) -} -``` - -Injector represents an interface for mapping and injecting dependencies into -structs and function arguments. - -#### func New - -```go -func New() Injector -``` -New returns a new Injector. - -#### type Invoker - -```go -type Invoker interface { - // Invoke attempts to call the interface{} provided as a function, - // providing dependencies for function arguments based on Type. Returns - // a slice of reflect.Value representing the returned values of the function. - // Returns an error if the injection fails. - Invoke(interface{}) ([]reflect.Value, error) -} -``` - -Invoker represents an interface for calling functions via reflection. - -#### type TypeMapper - -```go -type TypeMapper interface { - // Maps the interface{} value based on its immediate type from reflect.TypeOf. - Map(interface{}) TypeMapper - // Maps the interface{} value based on the pointer of an Interface provided. - // This is really only useful for mapping a value as an interface, as interfaces - // cannot at this time be referenced directly without a pointer. - MapTo(interface{}, interface{}) TypeMapper - // Provides a possibility to directly insert a mapping based on type and value. - // This makes it possible to directly map type arguments not possible to instantiate - // with reflect like unidirectional channels. - Set(reflect.Type, reflect.Value) TypeMapper - // Returns the Value that is mapped to the current type. Returns a zeroed Value if - // the Type has not been mapped. - Get(reflect.Type) reflect.Value -} -``` - -TypeMapper represents an interface for mapping interface{} values based on type. diff --git a/plugins/common/vendor/github.com/codegangsta/inject/inject.go b/plugins/common/vendor/github.com/codegangsta/inject/inject.go deleted file mode 100644 index 3ff713c8a..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/inject.go +++ /dev/null @@ -1,187 +0,0 @@ -// Package inject provides utilities for mapping and injecting dependencies in various ways. -package inject - -import ( - "fmt" - "reflect" -) - -// Injector represents an interface for mapping and injecting dependencies into structs -// and function arguments. -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent sets the parent of the injector. If the injector cannot find a - // dependency in its Type map it will check its parent before returning an - // error. - SetParent(Injector) -} - -// Applicator represents an interface for mapping dependencies to a struct. -type Applicator interface { - // Maps dependencies in the Type map to each field in the struct - // that is tagged with 'inject'. Returns an error if the injection - // fails. - Apply(interface{}) error -} - -// Invoker represents an interface for calling functions via reflection. -type Invoker interface { - // Invoke attempts to call the interface{} provided as a function, - // providing dependencies for function arguments based on Type. Returns - // a slice of reflect.Value representing the returned values of the function. - // Returns an error if the injection fails. - Invoke(interface{}) ([]reflect.Value, error) -} - -// TypeMapper represents an interface for mapping interface{} values based on type. -type TypeMapper interface { - // Maps the interface{} value based on its immediate type from reflect.TypeOf. - Map(interface{}) TypeMapper - // Maps the interface{} value based on the pointer of an Interface provided. - // This is really only useful for mapping a value as an interface, as interfaces - // cannot at this time be referenced directly without a pointer. - MapTo(interface{}, interface{}) TypeMapper - // Provides a possibility to directly insert a mapping based on type and value. - // This makes it possible to directly map type arguments not possible to instantiate - // with reflect like unidirectional channels. - Set(reflect.Type, reflect.Value) TypeMapper - // Returns the Value that is mapped to the current type. Returns a zeroed Value if - // the Type has not been mapped. - Get(reflect.Type) reflect.Value -} - -type injector struct { - values map[reflect.Type]reflect.Value - parent Injector -} - -// InterfaceOf dereferences a pointer to an Interface type. -// It panics if value is not an pointer to an interface. -func InterfaceOf(value interface{}) reflect.Type { - t := reflect.TypeOf(value) - - for t.Kind() == reflect.Ptr { - t = t.Elem() - } - - if t.Kind() != reflect.Interface { - panic("Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)") - } - - return t -} - -// New returns a new Injector. -func New() Injector { - return &injector{ - values: make(map[reflect.Type]reflect.Value), - } -} - -// Invoke attempts to call the interface{} provided as a function, -// providing dependencies for function arguments based on Type. -// Returns a slice of reflect.Value representing the returned values of the function. -// Returns an error if the injection fails. -// It panics if f is not a function -func (inj *injector) Invoke(f interface{}) ([]reflect.Value, error) { - t := reflect.TypeOf(f) - - var in = make([]reflect.Value, t.NumIn()) //Panic if t is not kind of Func - for i := 0; i < t.NumIn(); i++ { - argType := t.In(i) - val := inj.Get(argType) - if !val.IsValid() { - return nil, fmt.Errorf("Value not found for type %v", argType) - } - - in[i] = val - } - - return reflect.ValueOf(f).Call(in), nil -} - -// Maps dependencies in the Type map to each field in the struct -// that is tagged with 'inject'. -// Returns an error if the injection fails. -func (inj *injector) Apply(val interface{}) error { - v := reflect.ValueOf(val) - - for v.Kind() == reflect.Ptr { - v = v.Elem() - } - - if v.Kind() != reflect.Struct { - return nil // Should not panic here ? - } - - t := v.Type() - - for i := 0; i < v.NumField(); i++ { - f := v.Field(i) - structField := t.Field(i) - if f.CanSet() && (structField.Tag == "inject" || structField.Tag.Get("inject") != "") { - ft := f.Type() - v := inj.Get(ft) - if !v.IsValid() { - return fmt.Errorf("Value not found for type %v", ft) - } - - f.Set(v) - } - - } - - return nil -} - -// Maps the concrete value of val to its dynamic type using reflect.TypeOf, -// It returns the TypeMapper registered in. -func (i *injector) Map(val interface{}) TypeMapper { - i.values[reflect.TypeOf(val)] = reflect.ValueOf(val) - return i -} - -func (i *injector) MapTo(val interface{}, ifacePtr interface{}) TypeMapper { - i.values[InterfaceOf(ifacePtr)] = reflect.ValueOf(val) - return i -} - -// Maps the given reflect.Type to the given reflect.Value and returns -// the Typemapper the mapping has been registered in. -func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper { - i.values[typ] = val - return i -} - -func (i *injector) Get(t reflect.Type) reflect.Value { - val := i.values[t] - - if val.IsValid() { - return val - } - - // no concrete types found, try to find implementors - // if t is an interface - if t.Kind() == reflect.Interface { - for k, v := range i.values { - if k.Implements(t) { - val = v - break - } - } - } - - // Still no type found, try to look it up on the parent - if !val.IsValid() && i.parent != nil { - val = i.parent.Get(t) - } - - return val - -} - -func (i *injector) SetParent(parent Injector) { - i.parent = parent -} diff --git a/plugins/common/vendor/github.com/codegangsta/inject/inject_test.go b/plugins/common/vendor/github.com/codegangsta/inject/inject_test.go deleted file mode 100644 index eb94471d3..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/inject_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package inject_test - -import ( - "fmt" - "github.com/codegangsta/inject" - "reflect" - "testing" -) - -type SpecialString interface { -} - -type TestStruct struct { - Dep1 string `inject:"t" json:"-"` - Dep2 SpecialString `inject` - Dep3 string -} - -type Greeter struct { - Name string -} - -func (g *Greeter) String() string { - return "Hello, My name is" + g.Name -} - -/* Test Helpers */ -func expect(t *testing.T, a interface{}, b interface{}) { - if a != b { - t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -} - -func refute(t *testing.T, a interface{}, b interface{}) { - if a == b { - t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -} - -func Test_InjectorInvoke(t *testing.T) { - injector := inject.New() - expect(t, injector == nil, false) - - dep := "some dependency" - injector.Map(dep) - dep2 := "another dep" - injector.MapTo(dep2, (*SpecialString)(nil)) - dep3 := make(chan *SpecialString) - dep4 := make(chan *SpecialString) - typRecv := reflect.ChanOf(reflect.RecvDir, reflect.TypeOf(dep3).Elem()) - typSend := reflect.ChanOf(reflect.SendDir, reflect.TypeOf(dep4).Elem()) - injector.Set(typRecv, reflect.ValueOf(dep3)) - injector.Set(typSend, reflect.ValueOf(dep4)) - - _, err := injector.Invoke(func(d1 string, d2 SpecialString, d3 <-chan *SpecialString, d4 chan<- *SpecialString) { - expect(t, d1, dep) - expect(t, d2, dep2) - expect(t, reflect.TypeOf(d3).Elem(), reflect.TypeOf(dep3).Elem()) - expect(t, reflect.TypeOf(d4).Elem(), reflect.TypeOf(dep4).Elem()) - expect(t, reflect.TypeOf(d3).ChanDir(), reflect.RecvDir) - expect(t, reflect.TypeOf(d4).ChanDir(), reflect.SendDir) - }) - - expect(t, err, nil) -} - -func Test_InjectorInvokeReturnValues(t *testing.T) { - injector := inject.New() - expect(t, injector == nil, false) - - dep := "some dependency" - injector.Map(dep) - dep2 := "another dep" - injector.MapTo(dep2, (*SpecialString)(nil)) - - result, err := injector.Invoke(func(d1 string, d2 SpecialString) string { - expect(t, d1, dep) - expect(t, d2, dep2) - return "Hello world" - }) - - expect(t, result[0].String(), "Hello world") - expect(t, err, nil) -} - -func Test_InjectorApply(t *testing.T) { - injector := inject.New() - - injector.Map("a dep").MapTo("another dep", (*SpecialString)(nil)) - - s := TestStruct{} - err := injector.Apply(&s) - expect(t, err, nil) - - expect(t, s.Dep1, "a dep") - expect(t, s.Dep2, "another dep") - expect(t, s.Dep3, "") -} - -func Test_InterfaceOf(t *testing.T) { - iType := inject.InterfaceOf((*SpecialString)(nil)) - expect(t, iType.Kind(), reflect.Interface) - - iType = inject.InterfaceOf((**SpecialString)(nil)) - expect(t, iType.Kind(), reflect.Interface) - - // Expecting nil - defer func() { - rec := recover() - refute(t, rec, nil) - }() - iType = inject.InterfaceOf((*testing.T)(nil)) -} - -func Test_InjectorSet(t *testing.T) { - injector := inject.New() - typ := reflect.TypeOf("string") - typSend := reflect.ChanOf(reflect.SendDir, typ) - typRecv := reflect.ChanOf(reflect.RecvDir, typ) - - // instantiating unidirectional channels is not possible using reflect - // http://golang.org/src/pkg/reflect/value.go?s=60463:60504#L2064 - chanRecv := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, typ), 0) - chanSend := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, typ), 0) - - injector.Set(typSend, chanSend) - injector.Set(typRecv, chanRecv) - - expect(t, injector.Get(typSend).IsValid(), true) - expect(t, injector.Get(typRecv).IsValid(), true) - expect(t, injector.Get(chanSend.Type()).IsValid(), false) -} - -func Test_InjectorGet(t *testing.T) { - injector := inject.New() - - injector.Map("some dependency") - - expect(t, injector.Get(reflect.TypeOf("string")).IsValid(), true) - expect(t, injector.Get(reflect.TypeOf(11)).IsValid(), false) -} - -func Test_InjectorSetParent(t *testing.T) { - injector := inject.New() - injector.MapTo("another dep", (*SpecialString)(nil)) - - injector2 := inject.New() - injector2.SetParent(injector) - - expect(t, injector2.Get(inject.InterfaceOf((*SpecialString)(nil))).IsValid(), true) -} - -func TestInjectImplementors(t *testing.T) { - injector := inject.New() - g := &Greeter{"Jeremy"} - injector.Map(g) - - expect(t, injector.Get(inject.InterfaceOf((*fmt.Stringer)(nil))).IsValid(), true) -} diff --git a/plugins/common/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md b/plugins/common/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md deleted file mode 100644 index 0ac3d3f55..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md +++ /dev/null @@ -1,85 +0,0 @@ -# inject --- - import "github.com/codegangsta/inject" - -inject包提供了多种对实体的映射和依赖注入方式。 - -## 用法 - -#### func InterfaceOf - -```go -func InterfaceOf(value interface{}) reflect.Type -``` -函数InterfaceOf返回指向接口类型的指针。如果传入的value值不是指向接口的指针,将抛出一个panic异常。 - -#### type Applicator - -```go -type Applicator interface { - // 在Type map中维持对结构体中每个域的引用并用'inject'来标记 - // 如果注入失败将会返回一个error. - Apply(interface{}) error -} -``` - -Applicator接口表示到结构体的依赖映射关系。 - -#### type Injector - -```go -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent用来设置父injector. 如果在当前injector的Type map中找不到依赖, - // 将会继续从它的父injector中找,直到返回error. - SetParent(Injector) -} -``` - -Injector接口表示对结构体、函数参数的映射和依赖注入。 - -#### func New - -```go -func New() Injector -``` -New创建并返回一个Injector. - -#### type Invoker - -```go -type Invoker interface { - // Invoke尝试将interface{}作为一个函数来调用,并基于Type为函数提供参数。 - // 它将返回reflect.Value的切片,其中存放原函数的返回值。 - // 如果注入失败则返回error. - Invoke(interface{}) ([]reflect.Value, error) -} -``` - -Invoker接口表示通过反射进行函数调用。 - -#### type TypeMapper - -```go -type TypeMapper interface { - // 基于调用reflect.TypeOf得到的类型映射interface{}的值。 - Map(interface{}) TypeMapper - // 基于提供的接口的指针映射interface{}的值。 - // 该函数仅用来将一个值映射为接口,因为接口无法不通过指针而直接引用到。 - MapTo(interface{}, interface{}) TypeMapper - // 为直接插入基于类型和值的map提供一种可能性。 - // 它使得这一类直接映射成为可能:无法通过反射直接实例化的类型参数,如单向管道。 - Set(reflect.Type, reflect.Value) TypeMapper - // 返回映射到当前类型的Value. 如果Type没被映射,将返回对应的零值。 - Get(reflect.Type) reflect.Value -} -``` - -TypeMapper接口用来表示基于类型到接口值的映射。 - - -## 译者 - -张强 (qqbunny@yeah.net) \ No newline at end of file diff --git a/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh b/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh deleted file mode 100644 index 3cb21111c..000000000 --- a/plugins/common/vendor/github.com/codegangsta/inject/update_readme.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -go get github.com/robertkrimen/godocdown/godocdown -godocdown >README.md diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/LICENSE b/plugins/common/vendor/github.com/codeskyblue/go-sh/LICENSE deleted file mode 100644 index e06d20818..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/OLD_README.md b/plugins/common/vendor/github.com/codeskyblue/go-sh/OLD_README.md deleted file mode 100644 index 7e899402d..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/OLD_README.md +++ /dev/null @@ -1,69 +0,0 @@ -## OLD README -First give you a full example, I will explain every command below. - - session := sh.NewSession() - session.Env["PATH"] = "/usr/bin:/bin" - session.Stdout = os.Stdout - session.Stderr = os.Stderr - session.Alias("ll", "ls", "-l") - session.ShowCMD = true // enable for debug - var err error - err = session.Call("ll", "/") - if err != nil { - log.Fatal(err) - } - ret, err := session.Capture("pwd", sh.Dir("/home")) # wraper of session.Call - if err != nil { - log.Fatal(err) - } - # ret is "/home\n" - fmt.Println(ret) - -create a new Session - - session := sh.NewSession() - -use alias like this - - session.Alias("ll", "ls", "-l") # like alias ll='ls -l' - -set current env like this - - session.Env["BUILD_ID"] = "123" # like export BUILD_ID=123 - -set current directory - - session.Set(sh.Dir("/")) # like cd / - -pipe is also supported - - session.Command("echo", "hello\tworld").Command("cut", "-f2") - // output should be "world" - session.Run() - -test, the build in command support - - session.Test("d", "dir") // test dir - session.Test("f", "file) // test regular file - -with `Alias Env Set Call Capture Command` a shell scripts can be easily converted into golang program. below is a shell script. - - #!/bin/bash - - # - export PATH=/usr/bin:/bin - alias ll='ls -l' - cd /usr - if test -d "local" - then - ll local | awk '{print $1, $NF}' - fi - -convert to golang, will be - - s := sh.NewSession() - s.Env["PATH"] = "/usr/bin:/bin" - s.Set(sh.Dir("/usr")) - s.Alias("ll", "ls", "-l") - if s.Test("d", "local") { - s.Command("ll", "local").Command("awk", "{print $1, $NF}").Run() - } diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/README.md b/plugins/common/vendor/github.com/codeskyblue/go-sh/README.md deleted file mode 100644 index 28614708d..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/README.md +++ /dev/null @@ -1,85 +0,0 @@ -## go-sh -[![wercker status](https://app.wercker.com/status/009acbd4f00ccc6de7e2554e12a50d84/s "wercker status")](https://app.wercker.com/project/bykey/009acbd4f00ccc6de7e2554e12a50d84) -[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/codeskyblue/go-sh) - -*If you depend on the old api, see tag: v.0.1* - -install: `go get github.com/codeskyblue/go-sh` - -Pipe Example: - - package main - - import "github.com/codeskyblue/go-sh" - - func main() { - sh.Command("echo", "hello\tworld").Command("cut", "-f2").Run() - } - -Because I like os/exec, `go-sh` is very much modelled after it. However, `go-sh` provides a better experience. - -These are some of its features: - -* keep the variable environment (e.g. export) -* alias support (e.g. alias in shell) -* remember current dir -* pipe command -* shell build-in commands echo & test -* timeout support - -Examples are important: - - sh: echo hello - go: sh.Command("echo", "hello").Run() - - sh: export BUILD_ID=123 - go: s = sh.NewSession().SetEnv("BUILD_ID", "123") - - sh: alias ll='ls -l' - go: s = sh.NewSession().Alias('ll', 'ls', '-l') - - sh: (cd /; pwd) - go: sh.Command("pwd", sh.Dir("/")).Run() - - sh: test -d data || mkdir data - go: if ! sh.Test("dir", "data") { sh.Command("mkdir", "data").Run() } - - sh: cat first second | awk '{print $1}' - go: sh.Command("cat", "first", "second").Command("awk", "{print $1}").Run() - - sh: count=$(echo "one two three" | wc -w) - go: count, err := sh.Echo("one two three").Command("wc", "-w").Output() - - sh(in ubuntu): timeout 1s sleep 3 - go: c := sh.Command("sleep", "3"); c.Start(); c.WaitTimeout(time.Second) # default SIGKILL - go: out, err := sh.Command("sleep", "3").SetTimeout(time.Second).Output() # set session timeout and get output) - - sh: echo hello | cat - go: out, err := sh.Command("cat").SetInput("hello").Output() - - sh: cat # read from stdin - go: out, err := sh.Command("cat").SetStdin(os.Stdin).Output() - -If you need to keep env and dir, it is better to create a session - - session := sh.NewSession() - session.SetEnv("BUILD_ID", "123") - session.SetDir("/") - # then call cmd - session.Command("echo", "hello").Run() - # set ShowCMD to true for easily debug - session.ShowCMD = true - -for more information, it better to see docs. -[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/codeskyblue/go-sh) - -### contribute -If you love this project, starring it will encourage the coder. Pull requests are welcome. - -support the author: [alipay](https://me.alipay.com/goskyblue) - -### thanks -this project is based on . thanks for the author. - -# the reason to use Go shell -Sometimes we need to write shell scripts, but shell scripts are not good at working cross platform, Go, on the other hand, is good at that. Is there a good way to use Go to write shell like scripts? Using go-sh we can do this now. diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/example1.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/example/example1.go deleted file mode 100644 index cdc7f6c39..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/example1.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "github.com/codeskyblue/go-sh" -) - -func main() { - sh.Command("echo", "hello").Run() - out, err := sh.Command("echo", "hello").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println("output is", string(out)) - - var a int - sh.Command("echo", "2").UnmarshalJSON(&a) - fmt.Println("a =", a) - - s := sh.NewSession() - s.Alias("hi", "echo", "hi") - s.Command("hi", "boy").Run() - - fmt.Print("pwd = ") - s.Command("pwd", sh.Dir("/")).Run() - - if !sh.Test("dir", "data") { - sh.Command("echo", "mkdir", "data").Run() - } - - sh.Command("echo", "hello", "world"). - Command("awk", `{print "second arg is "$2}`).Run() - s.ShowCMD = true - s.Command("echo", "hello", "world"). - Command("awk", `{print "second arg is "$2}`).Run() - - s.SetEnv("BUILD_ID", "123").Command("bash", "-c", "echo $BUILD_ID").Run() - s.Command("bash", "-c", "echo current shell is $SHELL").Run() -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/less/less.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/example/less/less.go deleted file mode 100644 index ffced2e81..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/less/less.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/codeskyblue/go-sh" - -func main() { - sh.Command("less", "less.go").Run() -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go deleted file mode 100644 index b7ecd3bed..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "flag" - "fmt" - - "github.com/codeskyblue/go-sh" -) - -func main() { - flag.Parse() - if flag.NArg() != 1 { - fmt.Println("Usage: PROGRAM ") - return - } - sh.Command("tail", "-f", flag.Arg(0)).Run() -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go deleted file mode 100644 index 852908a47..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "fmt" - "time" - - sh "github.com/codeskyblue/go-sh" -) - -func main() { - c := sh.Command("sleep", "3") - c.Start() - err := c.WaitTimeout(time.Second * 1) - if err != nil { - fmt.Printf("timeout should happend: %v\n", err) - } - // timeout should be a session - out, err := sh.Command("sleep", "2").SetTimeout(time.Second).Output() - fmt.Printf("output:(%s), err(%v)\n", string(out), err) - - out, err = sh.Command("echo", "hello").SetTimeout(time.Second).Output() - fmt.Printf("output:(%s), err(%v)\n", string(out), err) -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/example_test.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/example_test.go deleted file mode 100644 index 5abfed64d..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/example_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package sh_test - -import ( - "fmt" - - "github.com/codeskyblue/go-sh" -) - -func ExampleCommand() { - out, err := sh.Command("echo", "hello").Output() - fmt.Println(string(out), err) -} - -func ExampleCommandPipe() { - out, err := sh.Command("echo", "-n", "hi").Command("wc", "-c").Output() - fmt.Println(string(out), err) -} - -func ExampleCommandSetDir() { - out, err := sh.Command("pwd", sh.Dir("/")).Output() - fmt.Println(string(out), err) -} - -func ExampleTest() { - if sh.Test("dir", "mydir") { - fmt.Println("mydir exists") - } -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/pipe.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/pipe.go deleted file mode 100644 index c35f4e2a0..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/pipe.go +++ /dev/null @@ -1,148 +0,0 @@ -package sh - -import ( - "bytes" - "encoding/json" - "encoding/xml" - "errors" - "io" - "os" - "strings" - "syscall" - "time" -) - -var ErrExecTimeout = errors.New("execute timeout") - -// unmarshal shell output to decode json -func (s *Session) UnmarshalJSON(data interface{}) (err error) { - bufrw := bytes.NewBuffer(nil) - s.Stdout = bufrw - if err = s.Run(); err != nil { - return - } - return json.NewDecoder(bufrw).Decode(data) -} - -// unmarshal command output into xml -func (s *Session) UnmarshalXML(data interface{}) (err error) { - bufrw := bytes.NewBuffer(nil) - s.Stdout = bufrw - if err = s.Run(); err != nil { - return - } - return xml.NewDecoder(bufrw).Decode(data) -} - -// start command -func (s *Session) Start() (err error) { - s.started = true - var rd *io.PipeReader - var wr *io.PipeWriter - var length = len(s.cmds) - if s.ShowCMD { - var cmds = make([]string, 0, 4) - for _, cmd := range s.cmds { - cmds = append(cmds, strings.Join(cmd.Args, " ")) - } - s.writePrompt(strings.Join(cmds, " | ")) - } - for index, cmd := range s.cmds { - if index == 0 { - cmd.Stdin = s.Stdin - } else { - cmd.Stdin = rd - } - if index != length { - rd, wr = io.Pipe() // create pipe - cmd.Stdout = wr - cmd.Stderr = os.Stderr - } - if index == length-1 { - cmd.Stdout = s.Stdout - cmd.Stderr = s.Stderr - } - err = cmd.Start() - if err != nil { - return - } - } - return -} - -// Should be call after Start() -// only catch the last command error -func (s *Session) Wait() (err error) { - for _, cmd := range s.cmds { - err = cmd.Wait() - wr, ok := cmd.Stdout.(*io.PipeWriter) - if ok { - wr.Close() - } - } - return err -} - -func (s *Session) Kill(sig os.Signal) { - for _, cmd := range s.cmds { - if cmd.Process != nil { - cmd.Process.Signal(sig) - } - } -} - -func (s *Session) WaitTimeout(timeout time.Duration) (err error) { - select { - case <-time.After(timeout): - s.Kill(syscall.SIGKILL) - return ErrExecTimeout - case err = <-Go(s.Wait): - return err - } -} - -func Go(f func() error) chan error { - ch := make(chan error) - go func() { - ch <- f() - }() - return ch -} - -func (s *Session) Run() (err error) { - if err = s.Start(); err != nil { - return - } - if s.timeout != time.Duration(0) { - return s.WaitTimeout(s.timeout) - } - return s.Wait() -} - -func (s *Session) Output() (out []byte, err error) { - oldout := s.Stdout - defer func() { - s.Stdout = oldout - }() - stdout := bytes.NewBuffer(nil) - s.Stdout = stdout - err = s.Run() - out = stdout.Bytes() - return -} - -func (s *Session) CombinedOutput() (out []byte, err error) { - oldout := s.Stdout - olderr := s.Stderr - defer func() { - s.Stdout = oldout - s.Stderr = olderr - }() - stdout := bytes.NewBuffer(nil) - s.Stdout = stdout - s.Stderr = stdout - - err = s.Run() - out = stdout.Bytes() - return -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/pipe_test.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/pipe_test.go deleted file mode 100644 index 8d0e22c0c..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/pipe_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package sh - -import ( - "encoding/xml" - "io" - "os" - "os/exec" - "strings" - "testing" - "time" -) - -func TestUnmarshalJSON(t *testing.T) { - var a int - s := NewSession() - s.ShowCMD = true - err := s.Command("echo", []string{"1"}).UnmarshalJSON(&a) - if err != nil { - t.Error(err) - } - if a != 1 { - t.Errorf("expect a tobe 1, but got %d", a) - } -} - -func TestUnmarshalXML(t *testing.T) { - s := NewSession() - xmlSample := ` -` - type server struct { - XMLName xml.Name `xml:"server"` - Version string `xml:"version,attr"` - } - data := &server{} - s.Command("echo", xmlSample).UnmarshalXML(data) - if data.Version != "1" { - t.Error(data) - } -} - -func TestPipe(t *testing.T) { - s := NewSession() - s.ShowCMD = true - s.Call("echo", "hello") - err := s.Command("echo", "hi").Command("cat", "-n").Start() - if err != nil { - t.Error(err) - } - err = s.Wait() - if err != nil { - t.Error(err) - } - out, err := s.Command("echo", []string{"hello"}).Output() - if err != nil { - t.Error(err) - } - if string(out) != "hello\n" { - t.Error("capture wrong output:", out) - } - s.Command("echo", []string{"hello\tworld"}).Command("cut", []string{"-f2"}).Run() -} - -func TestPipeCommand(t *testing.T) { - c1 := exec.Command("echo", "good") - rd, wr := io.Pipe() - c1.Stdout = wr - c2 := exec.Command("cat", "-n") - c2.Stdout = os.Stdout - c2.Stdin = rd - c1.Start() - c2.Start() - - c1.Wait() - wc, ok := c1.Stdout.(io.WriteCloser) - if ok { - wc.Close() - } - c2.Wait() -} - -func TestPipeInput(t *testing.T) { - s := NewSession() - s.ShowCMD = true - s.SetInput("first line\nsecond line\n") - out, err := s.Command("grep", "second").Output() - if err != nil { - t.Error(err) - } - if string(out) != "second line\n" { - t.Error("capture wrong output:", out) - } -} - -func TestTimeout(t *testing.T) { - s := NewSession() - err := s.Command("sleep", "2").Start() - if err != nil { - t.Fatal(err) - } - err = s.WaitTimeout(time.Second) - if err != ErrExecTimeout { - t.Fatal(err) - } -} - -func TestSetTimeout(t *testing.T) { - s := NewSession() - s.SetTimeout(time.Second) - defer s.SetTimeout(0) - err := s.Command("sleep", "2").Run() - if err != ErrExecTimeout { - t.Fatal(err) - } -} - -func TestCombinedOutput(t *testing.T) { - s := NewSession() - bytes, err := s.Command("sh", "-c", "echo stderr >&2 ; echo stdout").CombinedOutput() - if err != nil { - t.Error(err) - } - stringOutput := string(bytes) - if !(strings.Contains(stringOutput, "stdout") && strings.Contains(stringOutput, "stderr")) { - t.Errorf("expect output from both output streams, got '%s'", strings.TrimSpace(stringOutput)) - } -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/sh.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/sh.go deleted file mode 100644 index 15f1b85d5..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/sh.go +++ /dev/null @@ -1,200 +0,0 @@ -/* -Package go-sh is intented to make shell call with golang more easily. -Some usage is more similar to os/exec, eg: Run(), Output(), Command(name, args...) - -But with these similar function, pipe is added in and this package also got shell-session support. - -Why I love golang so much, because the usage of golang is simple, but the power is unlimited. I want to make this pakcage got the sample style like golang. - - // just like os/exec - sh.Command("echo", "hello").Run() - - // support pipe - sh.Command("echo", "hello").Command("wc", "-c").Run() - - // create a session to store dir and env - sh.NewSession().SetDir("/").Command("pwd") - - // shell buildin command - "test" - sh.Test("dir", "mydir") - - // like shell call: (cd /; pwd) - sh.Command("pwd", sh.Dir("/")) same with sh.Command(sh.Dir("/"), "pwd") - - // output to json and xml easily - v := map[string] int {} - err = sh.Command("echo", `{"number": 1}`).UnmarshalJSON(&v) -*/ -package sh - -import ( - "fmt" - "io" - "os" - "os/exec" - "reflect" - "strings" - "time" - - "github.com/codegangsta/inject" -) - -type Dir string - -type Session struct { - inj inject.Injector - alias map[string][]string - cmds []*exec.Cmd - dir Dir - started bool - Env map[string]string - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer - ShowCMD bool // enable for debug - timeout time.Duration -} - -func (s *Session) writePrompt(args ...interface{}) { - var ps1 = fmt.Sprintf("[golang-sh]$") - args = append([]interface{}{ps1}, args...) - fmt.Fprintln(s.Stderr, args...) -} - -func NewSession() *Session { - env := make(map[string]string) - for _, key := range []string{"PATH"} { - env[key] = os.Getenv(key) - } - s := &Session{ - inj: inject.New(), - alias: make(map[string][]string), - dir: Dir(""), - Stdin: strings.NewReader(""), - Stdout: os.Stdout, - Stderr: os.Stderr, - Env: env, - } - return s -} - -func InteractiveSession() *Session { - s := NewSession() - s.SetStdin(os.Stdin) - return s -} - -func Command(name string, a ...interface{}) *Session { - s := NewSession() - return s.Command(name, a...) -} - -func Echo(in string) *Session { - s := NewSession() - return s.SetInput(in) -} - -func (s *Session) Alias(alias, cmd string, args ...string) { - v := []string{cmd} - v = append(v, args...) - s.alias[alias] = v -} - -func (s *Session) Command(name string, a ...interface{}) *Session { - var args = make([]string, 0) - var sType = reflect.TypeOf("") - - // init cmd, args, dir, envs - // if not init, program may panic - s.inj.Map(name).Map(args).Map(s.dir).Map(map[string]string{}) - for _, v := range a { - switch reflect.TypeOf(v) { - case sType: - args = append(args, v.(string)) - default: - s.inj.Map(v) - } - } - if len(args) != 0 { - s.inj.Map(args) - } - s.inj.Invoke(s.appendCmd) - return s -} - -// combine Command and Run -func (s *Session) Call(name string, a ...interface{}) error { - return s.Command(name, a...).Run() -} - -/* -func (s *Session) Exec(cmd string, args ...string) error { - return s.Call(cmd, args) -} -*/ - -func (s *Session) SetEnv(key, value string) *Session { - s.Env[key] = value - return s -} - -func (s *Session) SetDir(dir string) *Session { - s.dir = Dir(dir) - return s -} - -func (s *Session) SetInput(in string) *Session { - s.Stdin = strings.NewReader(in) - return s -} - -func (s *Session) SetStdin(r io.Reader) *Session { - s.Stdin = r - return s -} - -func (s *Session) SetTimeout(d time.Duration) *Session { - s.timeout = d - return s -} - -func newEnviron(env map[string]string, inherit bool) []string { //map[string]string { - environ := make([]string, 0, len(env)) - if inherit { - for _, line := range os.Environ() { - for k, _ := range env { - if strings.HasPrefix(line, k+"=") { - goto CONTINUE - } - } - environ = append(environ, line) - CONTINUE: - } - } - for k, v := range env { - environ = append(environ, k+"="+v) - } - return environ -} - -func (s *Session) appendCmd(cmd string, args []string, cwd Dir, env map[string]string) { - if s.started { - s.started = false - s.cmds = make([]*exec.Cmd, 0) - } - for k, v := range s.Env { - if _, ok := env[k]; !ok { - env[k] = v - } - } - environ := newEnviron(s.Env, true) // true: inherit sys-env - v, ok := s.alias[cmd] - if ok { - cmd = v[0] - args = append(v[1:], args...) - } - c := exec.Command(cmd, args...) - c.Env = environ - c.Dir = string(cwd) - s.cmds = append(s.cmds, c) -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/sh_test.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/sh_test.go deleted file mode 100644 index be5c27998..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/sh_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package sh - -import ( - "fmt" - "log" - "runtime" - "strings" - "testing" -) - -func TestAlias(t *testing.T) { - s := NewSession() - s.Alias("gr", "echo", "hi") - out, err := s.Command("gr", "sky").Output() - if err != nil { - t.Error(err) - } - if string(out) != "hi sky\n" { - t.Errorf("expect 'hi sky' but got:%s", string(out)) - } -} - -func ExampleSession_Command() { - s := NewSession() - out, err := s.Command("echo", "hello").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: hello -} - -func ExampleSession_Command_pipe() { - s := NewSession() - out, err := s.Command("echo", "hello", "world").Command("awk", "{print $2}").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: world -} - -func ExampleSession_Alias() { - s := NewSession() - s.Alias("alias_echo_hello", "echo", "hello") - out, err := s.Command("alias_echo_hello", "world").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: hello world -} - -func TestEcho(t *testing.T) { - out, err := Echo("one two three").Command("wc", "-w").Output() - if err != nil { - t.Error(err) - } - if strings.TrimSpace(string(out)) != "3" { - t.Errorf("expect '3' but got:%s", string(out)) - } -} - -func TestSession(t *testing.T) { - if runtime.GOOS == "windows" { - t.Log("ignore test on windows") - return - } - session := NewSession() - session.ShowCMD = true - err := session.Call("pwd") - if err != nil { - t.Error(err) - } - out, err := session.SetDir("/").Command("pwd").Output() - if err != nil { - t.Error(err) - } - if string(out) != "/\n" { - t.Errorf("expect /, but got %s", string(out)) - } -} - -/* - #!/bin/bash - - # - export PATH=/usr/bin:/bin - alias ll='ls -l' - cd /usr - if test -d "local" - then - ll local | awk '{print $1, $NF}' | grep bin - fi -*/ -func Example(t *testing.T) { - s := NewSession() - //s.ShowCMD = true - s.Env["PATH"] = "/usr/bin:/bin" - s.SetDir("/bin") - s.Alias("ll", "ls", "-l") - - if s.Test("d", "local") { - //s.Command("ll", []string{"local"}).Command("awk", []string{"{print $1, $NF}"}).Command("grep", []string{"bin"}).Run() - s.Command("ll", "local").Command("awk", "{print $1, $NF}").Command("grep", "bin").Run() - } -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/test.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/test.go deleted file mode 100644 index b9d310527..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/test.go +++ /dev/null @@ -1,64 +0,0 @@ -package sh - -import ( - "os" - "path/filepath" -) - -func filetest(name string, modemask os.FileMode) (match bool, err error) { - fi, err := os.Stat(name) - if err != nil { - return - } - match = (fi.Mode() & modemask) == modemask - return -} - -func (s *Session) pwd() string { - dir := string(s.dir) - if dir == "" { - dir, _ = os.Getwd() - } - return dir -} - -func (s *Session) abspath(name string) string { - if filepath.IsAbs(name) { - return name - } - return filepath.Join(s.pwd(), name) -} - -func init() { - //log.SetFlags(log.Lshortfile | log.LstdFlags) -} - -// expression can be dir, file, link -func (s *Session) Test(expression string, argument string) bool { - var err error - var fi os.FileInfo - fi, err = os.Lstat(s.abspath(argument)) - switch expression { - case "d", "dir": - return err == nil && fi.IsDir() - case "f", "file": - return err == nil && fi.Mode().IsRegular() - case "x", "executable": - /* - fmt.Println(expression, argument) - if err == nil { - fmt.Println(fi.Mode()) - } - */ - return err == nil && fi.Mode()&os.FileMode(0100) != 0 - case "L", "link": - return err == nil && fi.Mode()&os.ModeSymlink != 0 - } - return false -} - -// expression can be d,dir, f,file, link -func Test(exp string, arg string) bool { - s := NewSession() - return s.Test(exp, arg) -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/test_test.go b/plugins/common/vendor/github.com/codeskyblue/go-sh/test_test.go deleted file mode 100644 index 15225aa9a..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/test_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package sh_test - -import ( - "testing" - - "github.com/codeskyblue/go-sh" -) - -var s = sh.NewSession() - -type T struct{ *testing.T } - -func NewT(t *testing.T) *T { - return &T{t} -} - -func (t *T) checkTest(exp string, arg string, result bool) { - r := s.Test(exp, arg) - if r != result { - t.Errorf("test -%s %s, %v != %v", exp, arg, r, result) - } -} - -func TestTest(i *testing.T) { - t := NewT(i) - t.checkTest("d", "../go-sh", true) - t.checkTest("d", "./yymm", false) - - // file test - t.checkTest("f", "testdata/hello.txt", true) - t.checkTest("f", "testdata/xxxxx", false) - t.checkTest("f", "testdata/yymm", false) - - // link test - t.checkTest("link", "testdata/linkfile", true) - t.checkTest("link", "testdata/xxxxxlinkfile", false) - t.checkTest("link", "testdata/hello.txt", false) - - // executable test - t.checkTest("x", "testdata/executable", true) - t.checkTest("x", "testdata/xxxxx", false) - t.checkTest("x", "testdata/hello.txt", false) -} - -func ExampleShellTest(t *testing.T) { - // test -L - sh.Test("link", "testdata/linkfile") - sh.Test("L", "testdata/linkfile") - // test -f - sh.Test("file", "testdata/file") - sh.Test("f", "testdata/file") - // test -x - sh.Test("executable", "testdata/binfile") - sh.Test("x", "testdata/binfile") - // test -d - sh.Test("dir", "testdata/dir") - sh.Test("d", "testdata/dir") -} diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/executable b/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/executable deleted file mode 100755 index e69de29bb..000000000 diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/hello.txt b/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/hello.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/linkfile b/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/linkfile deleted file mode 120000 index a5162f80d..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/testdata/linkfile +++ /dev/null @@ -1 +0,0 @@ -hello.txt \ No newline at end of file diff --git a/plugins/common/vendor/github.com/codeskyblue/go-sh/wercker.yml b/plugins/common/vendor/github.com/codeskyblue/go-sh/wercker.yml deleted file mode 100644 index 72c47020f..000000000 --- a/plugins/common/vendor/github.com/codeskyblue/go-sh/wercker.yml +++ /dev/null @@ -1,28 +0,0 @@ -box: wercker/golang -# Build definition -build: - # The steps that will be executed on build - steps: - # Sets the go workspace and places you package - # at the right place in the workspace tree - - setup-go-workspace - - # Gets the dependencies - - script: - name: go get - code: | - cd $WERCKER_SOURCE_DIR - go version - go get -t . - - # Build the project - - script: - name: go build - code: | - go build . - - # Test the project - - script: - name: go test - code: | - go test -v ./... diff --git a/plugins/config/glide.lock b/plugins/config/glide.lock deleted file mode 100644 index eca79f070..000000000 --- a/plugins/config/glide.lock +++ /dev/null @@ -1,8 +0,0 @@ -hash: dd48defef474bdf5c6e47281a256ca941d71fe1e637d11443fb49acf3e4b5326 -updated: 2017-09-23T16:25:15.559883959-04:00 -imports: -- name: github.com/joho/godotenv - version: a79fa1e548e2c689c241d10173efd51e5d689d5b -- name: github.com/ryanuber/columnize - version: abc90934186a77966e2beeac62ed966aac0561d5 -testImports: [] diff --git a/plugins/config/glide.yaml b/plugins/config/glide.yaml deleted file mode 100644 index bf96c156b..000000000 --- a/plugins/config/glide.yaml +++ /dev/null @@ -1,8 +0,0 @@ -package: github.com/dokku/dokku/plugins/config -ignore: -- github.com/dokku/dokku/plugins/common -- github.com/onsi/gomega -import: -- package: github.com/ryanuber/columnize -- package: github.com/joho/godotenv - version: ^1.2.0 diff --git a/plugins/config/go.mod b/plugins/config/go.mod new file mode 100644 index 000000000..00a16985b --- /dev/null +++ b/plugins/config/go.mod @@ -0,0 +1,12 @@ +module github.com/dokku/dokku/plugins/config + +go 1.14 + +require ( + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 // indirect + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/joho/godotenv v1.3.0 + github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 +) + +replace github.com/dokku/dokku/plugins/common => ../common diff --git a/plugins/config/go.sum b/plugins/config/go.sum new file mode 100644 index 000000000..6d8e1933b --- /dev/null +++ b/plugins/config/go.sum @@ -0,0 +1,47 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/config/src/commands/commands.go b/plugins/config/src/commands/commands.go index 2a35a4cca..fef47579c 100644 --- a/plugins/config/src/commands/commands.go +++ b/plugins/config/src/commands/commands.go @@ -9,7 +9,6 @@ import ( "github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/config" - columnize "github.com/ryanuber/columnize" ) const ( @@ -74,11 +73,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/config/vendor/github.com/joho/godotenv/.gitignore b/plugins/config/vendor/github.com/joho/godotenv/.gitignore deleted file mode 100644 index e43b0f988..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.DS_Store diff --git a/plugins/config/vendor/github.com/joho/godotenv/.travis.yml b/plugins/config/vendor/github.com/joho/godotenv/.travis.yml deleted file mode 100644 index df65350ba..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go - -go: - - 1.8 - -os: - - linux - - osx diff --git a/plugins/config/vendor/github.com/joho/godotenv/LICENCE b/plugins/config/vendor/github.com/joho/godotenv/LICENCE deleted file mode 100644 index e7ddd51be..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/LICENCE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2013 John Barton - -MIT License - -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/plugins/config/vendor/github.com/joho/godotenv/README.md b/plugins/config/vendor/github.com/joho/godotenv/README.md deleted file mode 100644 index 1a20c78dc..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/README.md +++ /dev/null @@ -1,163 +0,0 @@ -# GoDotEnv [![Build Status](https://travis-ci.org/joho/godotenv.svg?branch=master)](https://travis-ci.org/joho/godotenv) [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4?svg=true)](https://ci.appveyor.com/project/joho/godotenv) [![Go Report Card](https://goreportcard.com/badge/github.com/joho/godotenv)](https://goreportcard.com/report/github.com/joho/godotenv) - -A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file) - -From the original Library: - -> Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables. -> -> But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a .env file into ENV when the environment is bootstrapped. - -It can be used as a library (for loading in env for your own daemons etc) or as a bin command. - -There is test coverage and CI for both linuxish and windows environments, but I make no guarantees about the bin version working on windows. - -## Installation - -As a library - -```shell -go get github.com/joho/godotenv -``` - -or if you want to use it as a bin command -```shell -go get github.com/joho/godotenv/cmd/godotenv -``` - -## Usage - -Add your application configuration to your `.env` file in the root of your project: - -```shell -S3_BUCKET=YOURS3BUCKET -SECRET_KEY=YOURSECRETKEYGOESHERE -``` - -Then in your Go app you can do something like - -```go -package main - -import ( - "github.com/joho/godotenv" - "log" - "os" -) - -func main() { - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file") - } - - s3Bucket := os.Getenv("S3_BUCKET") - secretKey := os.Getenv("SECRET_KEY") - - // now do something with s3 or whatever -} -``` - -If you're even lazier than that, you can just take advantage of the autoload package which will read in `.env` on import - -```go -import _ "github.com/joho/godotenv/autoload" -``` - -While `.env` in the project root is the default, you don't have to be constrained, both examples below are 100% legit - -```go -_ = godotenv.Load("somerandomfile") -_ = godotenv.Load("filenumberone.env", "filenumbertwo.env") -``` - -If you want to be really fancy with your env file you can do comments and exports (below is a valid env file) - -```shell -# I am a comment and that is OK -SOME_VAR=someval -FOO=BAR # comments at line end are OK too -export BAR=BAZ -``` - -Or finally you can do YAML(ish) style - -```yaml -FOO: bar -BAR: baz -``` - -as a final aside, if you don't want godotenv munging your env you can just get a map back instead - -```go -var myEnv map[string]string -myEnv, err := godotenv.Read() - -s3Bucket := myEnv["S3_BUCKET"] -``` - -... or from an `io.Reader` instead of a local file - -```go -reader := getRemoteFile() -myEnv, err := godotenv.Parse(reader) -``` - -... or from a `string` if you so desire - -```go -content := getRemoteFileContent() -myEnv, err := godotenv.Unmarshal(content) -``` - -### Command Mode - -Assuming you've installed the command as above and you've got `$GOPATH/bin` in your `$PATH` - -``` -godotenv -f /some/path/to/.env some_command with some args -``` - -If you don't specify `-f` it will fall back on the default of loading `.env` in `PWD` - -### Writing Env Files - -Godotenv can also write a map representing the environment to a correctly-formatted and escaped file - -```go -env, err := godotenv.Unmarshal("KEY=value") -err := godotenv.Write(env, "./.env") -``` - -... or to a string - -```go -env, err := godotenv.Unmarshal("KEY=value") -content, err := godotenv.Marshal(env) -``` - -## Contributing - -Contributions are most welcome! The parser itself is pretty stupidly naive and I wouldn't be surprised if it breaks with edge cases. - -*code changes without tests will not be accepted* - -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Added some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - -## Releases - -Releases should follow [Semver](http://semver.org/) though the first couple of releases are `v1` and `v1.1`. - -Use [annotated tags for all releases](https://github.com/joho/godotenv/issues/30). Example `git tag -a v1.2.1` - -## CI - -Linux: [![Build Status](https://travis-ci.org/joho/godotenv.svg?branch=master)](https://travis-ci.org/joho/godotenv) Windows: [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4)](https://ci.appveyor.com/project/joho/godotenv) - -## Who? - -The original library [dotenv](https://github.com/bkeepers/dotenv) was written by [Brandon Keepers](http://opensoul.org/), and this port was done by [John Barton](http://whoisjohnbarton.com) based off the tests/fixtures in the original library. diff --git a/plugins/config/vendor/github.com/joho/godotenv/autoload/autoload.go b/plugins/config/vendor/github.com/joho/godotenv/autoload/autoload.go deleted file mode 100644 index fbcd2bdf8..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/autoload/autoload.go +++ /dev/null @@ -1,15 +0,0 @@ -package autoload - -/* - You can just read the .env file on import just by doing - - import _ "github.com/joho/godotenv/autoload" - - And bob's your mother's brother -*/ - -import "github.com/joho/godotenv" - -func init() { - godotenv.Load() -} diff --git a/plugins/config/vendor/github.com/joho/godotenv/cmd/godotenv/cmd.go b/plugins/config/vendor/github.com/joho/godotenv/cmd/godotenv/cmd.go deleted file mode 100644 index 04a9f6497..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/cmd/godotenv/cmd.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "log" - - "strings" - - "github.com/joho/godotenv" -) - -func main() { - var showHelp bool - flag.BoolVar(&showHelp, "h", false, "show help") - var rawEnvFilenames string - flag.StringVar(&rawEnvFilenames, "f", "", "comma separated paths to .env files") - - flag.Parse() - - usage := ` -Run a process with a env setup from a .env file - -godotenv [-f ENV_FILE_PATHS] COMMAND_ARGS - -ENV_FILE_PATHS: comma separated paths to .env files -COMMAND_ARGS: command and args you want to run - -example - godotenv -f /path/to/something/.env,/another/path/.env fortune -` - // if no args or -h flag - // print usage and return - args := flag.Args() - if showHelp || len(args) == 0 { - fmt.Println(usage) - return - } - - // load env - var envFilenames []string - if rawEnvFilenames != "" { - envFilenames = strings.Split(rawEnvFilenames, ",") - } - - // take rest of args and "exec" them - cmd := args[0] - cmdArgs := args[1:] - - err := godotenv.Exec(envFilenames, cmd, cmdArgs) - if err != nil { - log.Fatal(err) - } -} diff --git a/plugins/config/vendor/github.com/joho/godotenv/fixtures/equals.env b/plugins/config/vendor/github.com/joho/godotenv/fixtures/equals.env deleted file mode 100644 index 594c5328a..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/fixtures/equals.env +++ /dev/null @@ -1,2 +0,0 @@ -export OPTION_A='postgres://localhost:5432/database?sslmode=disable' - diff --git a/plugins/config/vendor/github.com/joho/godotenv/fixtures/exported.env b/plugins/config/vendor/github.com/joho/godotenv/fixtures/exported.env deleted file mode 100644 index 5821377c7..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/fixtures/exported.env +++ /dev/null @@ -1,2 +0,0 @@ -export OPTION_A=2 -export OPTION_B='\n' diff --git a/plugins/config/vendor/github.com/joho/godotenv/fixtures/invalid1.env b/plugins/config/vendor/github.com/joho/godotenv/fixtures/invalid1.env deleted file mode 100644 index 38f7e0e8b..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/fixtures/invalid1.env +++ /dev/null @@ -1,2 +0,0 @@ -INVALID LINE -foo=bar diff --git a/plugins/config/vendor/github.com/joho/godotenv/fixtures/plain.env b/plugins/config/vendor/github.com/joho/godotenv/fixtures/plain.env deleted file mode 100644 index 43f7e44cc..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/fixtures/plain.env +++ /dev/null @@ -1,7 +0,0 @@ -OPTION_A=1 -OPTION_B=2 -OPTION_C= 3 -OPTION_D =4 -OPTION_E = 5 -OPTION_F = -OPTION_G= \ No newline at end of file diff --git a/plugins/config/vendor/github.com/joho/godotenv/fixtures/quoted.env b/plugins/config/vendor/github.com/joho/godotenv/fixtures/quoted.env deleted file mode 100644 index a03ce249b..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/fixtures/quoted.env +++ /dev/null @@ -1,8 +0,0 @@ -OPTION_A='1' -OPTION_B='2' -OPTION_C='' -OPTION_D='\n' -OPTION_E="1" -OPTION_F="2" -OPTION_G="" -OPTION_H="\n" diff --git a/plugins/config/vendor/github.com/joho/godotenv/godotenv.go b/plugins/config/vendor/github.com/joho/godotenv/godotenv.go deleted file mode 100644 index 48ae78c5d..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/godotenv.go +++ /dev/null @@ -1,314 +0,0 @@ -// Package godotenv is a go port of the ruby dotenv library (https://github.com/bkeepers/dotenv) -// -// Examples/readme can be found on the github page at https://github.com/joho/godotenv -// -// The TL;DR is that you make a .env file that looks something like -// -// SOME_ENV_VAR=somevalue -// -// and then in your go code you can call -// -// godotenv.Load() -// -// and all the env vars declared in .env will be available through os.Getenv("SOME_ENV_VAR") -package godotenv - -import ( - "bufio" - "errors" - "fmt" - "io" - "os" - "os/exec" - "regexp" - "sort" - "strings" -) - -const doubleQuoteSpecialChars = "\\\n\r\"!$`" - -// Load will read your env file(s) and load them into ENV for this process. -// -// Call this function as close as possible to the start of your program (ideally in main) -// -// If you call Load without any args it will default to loading .env in the current path -// -// You can otherwise tell it which files to load (there can be more than one) like -// -// godotenv.Load("fileone", "filetwo") -// -// It's important to note that it WILL NOT OVERRIDE an env variable that already exists - consider the .env file to set dev vars or sensible defaults -func Load(filenames ...string) (err error) { - filenames = filenamesOrDefault(filenames) - - for _, filename := range filenames { - err = loadFile(filename, false) - if err != nil { - return // return early on a spazout - } - } - return -} - -// Overload will read your env file(s) and load them into ENV for this process. -// -// Call this function as close as possible to the start of your program (ideally in main) -// -// If you call Overload without any args it will default to loading .env in the current path -// -// You can otherwise tell it which files to load (there can be more than one) like -// -// godotenv.Overload("fileone", "filetwo") -// -// It's important to note this WILL OVERRIDE an env variable that already exists - consider the .env file to forcefilly set all vars. -func Overload(filenames ...string) (err error) { - filenames = filenamesOrDefault(filenames) - - for _, filename := range filenames { - err = loadFile(filename, true) - if err != nil { - return // return early on a spazout - } - } - return -} - -// Read all env (with same file loading semantics as Load) but return values as -// a map rather than automatically writing values into env -func Read(filenames ...string) (envMap map[string]string, err error) { - filenames = filenamesOrDefault(filenames) - envMap = make(map[string]string) - - for _, filename := range filenames { - individualEnvMap, individualErr := readFile(filename) - - if individualErr != nil { - err = individualErr - return // return early on a spazout - } - - for key, value := range individualEnvMap { - envMap[key] = value - } - } - - return -} - -// Parse reads an env file from io.Reader, returning a map of keys and values. -func Parse(r io.Reader) (envMap map[string]string, err error) { - envMap = make(map[string]string) - - var lines []string - scanner := bufio.NewScanner(r) - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - - if err = scanner.Err(); err != nil { - return - } - - for _, fullLine := range lines { - if !isIgnoredLine(fullLine) { - var key, value string - key, value, err = parseLine(fullLine) - - if err != nil { - return - } - envMap[key] = value - } - } - return -} - -//Unmarshal reads an env file from a string, returning a map of keys and values. -func Unmarshal(str string) (envMap map[string]string, err error) { - return Parse(strings.NewReader(str)) -} - -// Exec loads env vars from the specified filenames (empty map falls back to default) -// then executes the cmd specified. -// -// Simply hooks up os.Stdin/err/out to the command and calls Run() -// -// If you want more fine grained control over your command it's recommended -// that you use `Load()` or `Read()` and the `os/exec` package yourself. -func Exec(filenames []string, cmd string, cmdArgs []string) error { - Load(filenames...) - - command := exec.Command(cmd, cmdArgs...) - command.Stdin = os.Stdin - command.Stdout = os.Stdout - command.Stderr = os.Stderr - return command.Run() -} - -// Write serializes the given environment and writes it to a file -func Write(envMap map[string]string, filename string) error { - content, error := Marshal(envMap) - if error != nil { - return error - } - file, error := os.Create(filename) - if error != nil { - return error - } - _, err := file.WriteString(content) - return err -} - -// Marshal outputs the given environment as a dotenv-formatted environment file. -// Each line is in the format: KEY="VALUE" where VALUE is backslash-escaped. -func Marshal(envMap map[string]string) (string, error) { - lines := make([]string, 0, len(envMap)) - for k, v := range envMap { - lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v))) - } - sort.Strings(lines) - return strings.Join(lines, "\n"), nil -} - -func filenamesOrDefault(filenames []string) []string { - if len(filenames) == 0 { - return []string{".env"} - } - return filenames -} - -func loadFile(filename string, overload bool) error { - envMap, err := readFile(filename) - if err != nil { - return err - } - - currentEnv := map[string]bool{} - rawEnv := os.Environ() - for _, rawEnvLine := range rawEnv { - key := strings.Split(rawEnvLine, "=")[0] - currentEnv[key] = true - } - - for key, value := range envMap { - if !currentEnv[key] || overload { - os.Setenv(key, value) - } - } - - return nil -} - -func readFile(filename string) (envMap map[string]string, err error) { - file, err := os.Open(filename) - if err != nil { - return - } - defer file.Close() - - return Parse(file) -} - -func parseLine(line string) (key string, value string, err error) { - if len(line) == 0 { - err = errors.New("zero length string") - return - } - - // ditch the comments (but keep quoted hashes) - if strings.Contains(line, "#") { - segmentsBetweenHashes := strings.Split(line, "#") - quotesAreOpen := false - var segmentsToKeep []string - for _, segment := range segmentsBetweenHashes { - if strings.Count(segment, "\"") == 1 || strings.Count(segment, "'") == 1 { - if quotesAreOpen { - quotesAreOpen = false - segmentsToKeep = append(segmentsToKeep, segment) - } else { - quotesAreOpen = true - } - } - - if len(segmentsToKeep) == 0 || quotesAreOpen { - segmentsToKeep = append(segmentsToKeep, segment) - } - } - - line = strings.Join(segmentsToKeep, "#") - } - - firstEquals := strings.Index(line, "=") - firstColon := strings.Index(line, ":") - splitString := strings.SplitN(line, "=", 2) - if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) { - //this is a yaml-style line - splitString = strings.SplitN(line, ":", 2) - } - - if len(splitString) != 2 { - err = errors.New("Can't separate key from value") - return - } - - // Parse the key - key = splitString[0] - if strings.HasPrefix(key, "export") { - key = strings.TrimPrefix(key, "export") - } - key = strings.Trim(key, " ") - - // Parse the value - value = parseValue(splitString[1]) - return -} - -func parseValue(value string) string { - - // trim - value = strings.Trim(value, " ") - - // check if we've got quoted values or possible escapes - if len(value) > 1 { - first := string(value[0:1]) - last := string(value[len(value)-1:]) - if first == last && strings.ContainsAny(first, `"'`) { - // pull the quotes off the edges - value = value[1 : len(value)-1] - // handle escapes - escapeRegex := regexp.MustCompile(`\\.`) - value = escapeRegex.ReplaceAllStringFunc(value, func(match string) string { - c := strings.TrimPrefix(match, `\`) - switch c { - case "n": - return "\n" - case "r": - return "\r" - default: - return c - } - }) - } - } - - return value -} - -func isIgnoredLine(line string) bool { - trimmedLine := strings.Trim(line, " \n\t") - return len(trimmedLine) == 0 || strings.HasPrefix(trimmedLine, "#") -} - -func doubleQuoteEscape(line string) string { - for _, c := range doubleQuoteSpecialChars { - toReplace := "\\" + string(c) - if c == '\n' { - toReplace = `\n` - } - if c == '\r' { - toReplace = `\r` - } - line = strings.Replace(line, string(c), toReplace, -1) - } - return line -} diff --git a/plugins/config/vendor/github.com/joho/godotenv/godotenv_test.go b/plugins/config/vendor/github.com/joho/godotenv/godotenv_test.go deleted file mode 100644 index cd9e2f309..000000000 --- a/plugins/config/vendor/github.com/joho/godotenv/godotenv_test.go +++ /dev/null @@ -1,375 +0,0 @@ -package godotenv - -import ( - "bytes" - "fmt" - "os" - "reflect" - "testing" -) - -var noopPresets = make(map[string]string) - -func parseAndCompare(t *testing.T, rawEnvLine string, expectedKey string, expectedValue string) { - key, value, _ := parseLine(rawEnvLine) - if key != expectedKey || value != expectedValue { - t.Errorf("Expected '%v' to parse as '%v' => '%v', got '%v' => '%v' instead", rawEnvLine, expectedKey, expectedValue, key, value) - } -} - -func loadEnvAndCompareValues(t *testing.T, loader func(files ...string) error, envFileName string, expectedValues map[string]string, presets map[string]string) { - // first up, clear the env - os.Clearenv() - - for k, v := range presets { - os.Setenv(k, v) - } - - err := loader(envFileName) - if err != nil { - t.Fatalf("Error loading %v", envFileName) - } - - for k := range expectedValues { - envValue := os.Getenv(k) - v := expectedValues[k] - if envValue != v { - t.Errorf("Mismatch for key '%v': expected '%v' got '%v'", k, v, envValue) - } - } -} - -func TestLoadWithNoArgsLoadsDotEnv(t *testing.T) { - err := Load() - pathError := err.(*os.PathError) - if pathError == nil || pathError.Op != "open" || pathError.Path != ".env" { - t.Errorf("Didn't try and open .env by default") - } -} - -func TestOverloadWithNoArgsOverloadsDotEnv(t *testing.T) { - err := Overload() - pathError := err.(*os.PathError) - if pathError == nil || pathError.Op != "open" || pathError.Path != ".env" { - t.Errorf("Didn't try and open .env by default") - } -} - -func TestLoadFileNotFound(t *testing.T) { - err := Load("somefilethatwillneverexistever.env") - if err == nil { - t.Error("File wasn't found but Load didn't return an error") - } -} - -func TestOverloadFileNotFound(t *testing.T) { - err := Overload("somefilethatwillneverexistever.env") - if err == nil { - t.Error("File wasn't found but Overload didn't return an error") - } -} - -func TestReadPlainEnv(t *testing.T) { - envFileName := "fixtures/plain.env" - expectedValues := map[string]string{ - "OPTION_A": "1", - "OPTION_B": "2", - "OPTION_C": "3", - "OPTION_D": "4", - "OPTION_E": "5", - "OPTION_F": "", - "OPTION_G": "", - } - - envMap, err := Read(envFileName) - if err != nil { - t.Error("Error reading file") - } - - if len(envMap) != len(expectedValues) { - t.Error("Didn't get the right size map back") - } - - for key, value := range expectedValues { - if envMap[key] != value { - t.Error("Read got one of the keys wrong") - } - } -} - -func TestParse(t *testing.T) { - envMap, err := Parse(bytes.NewReader([]byte("ONE=1\nTWO='2'\nTHREE = \"3\""))) - expectedValues := map[string]string{ - "ONE": "1", - "TWO": "2", - "THREE": "3", - } - if err != nil { - t.Fatalf("error parsing env: %v", err) - } - for key, value := range expectedValues { - if envMap[key] != value { - t.Errorf("expected %s to be %s, got %s", key, value, envMap[key]) - } - } -} - -func TestLoadDoesNotOverride(t *testing.T) { - envFileName := "fixtures/plain.env" - - // ensure NO overload - presets := map[string]string{ - "OPTION_A": "do_not_override", - "OPTION_B": "", - } - - expectedValues := map[string]string{ - "OPTION_A": "do_not_override", - "OPTION_B": "", - } - loadEnvAndCompareValues(t, Load, envFileName, expectedValues, presets) -} - -func TestOveroadDoesOverride(t *testing.T) { - envFileName := "fixtures/plain.env" - - // ensure NO overload - presets := map[string]string{ - "OPTION_A": "do_not_override", - } - - expectedValues := map[string]string{ - "OPTION_A": "1", - } - loadEnvAndCompareValues(t, Overload, envFileName, expectedValues, presets) -} - -func TestLoadPlainEnv(t *testing.T) { - envFileName := "fixtures/plain.env" - expectedValues := map[string]string{ - "OPTION_A": "1", - "OPTION_B": "2", - "OPTION_C": "3", - "OPTION_D": "4", - "OPTION_E": "5", - } - - loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets) -} - -func TestLoadExportedEnv(t *testing.T) { - envFileName := "fixtures/exported.env" - expectedValues := map[string]string{ - "OPTION_A": "2", - "OPTION_B": "\n", - } - - loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets) -} - -func TestLoadEqualsEnv(t *testing.T) { - envFileName := "fixtures/equals.env" - expectedValues := map[string]string{ - "OPTION_A": "postgres://localhost:5432/database?sslmode=disable", - } - - loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets) -} - -func TestLoadQuotedEnv(t *testing.T) { - envFileName := "fixtures/quoted.env" - expectedValues := map[string]string{ - "OPTION_A": "1", - "OPTION_B": "2", - "OPTION_C": "", - "OPTION_D": "\n", - "OPTION_E": "1", - "OPTION_F": "2", - "OPTION_G": "", - "OPTION_H": "\n", - } - - loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets) -} - -func TestActualEnvVarsAreLeftAlone(t *testing.T) { - os.Clearenv() - os.Setenv("OPTION_A", "actualenv") - _ = Load("fixtures/plain.env") - - if os.Getenv("OPTION_A") != "actualenv" { - t.Error("An ENV var set earlier was overwritten") - } -} - -func TestParsing(t *testing.T) { - // unquoted values - parseAndCompare(t, "FOO=bar", "FOO", "bar") - - // parses values with spaces around equal sign - parseAndCompare(t, "FOO =bar", "FOO", "bar") - parseAndCompare(t, "FOO= bar", "FOO", "bar") - - // parses double quoted values - parseAndCompare(t, `FOO="bar"`, "FOO", "bar") - - // parses single quoted values - parseAndCompare(t, "FOO='bar'", "FOO", "bar") - - // parses escaped double quotes - parseAndCompare(t, `FOO="escaped\"bar"`, "FOO", `escaped"bar`) - - // parses single quotes inside double quotes - parseAndCompare(t, `FOO="'d'"`, "FOO", `'d'`) - - // parses yaml style options - parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1") - - //parses yaml values with equal signs - parseAndCompare(t, "OPTION_A: Foo=bar", "OPTION_A", "Foo=bar") - - // parses non-yaml options with colons - parseAndCompare(t, "OPTION_A=1:B", "OPTION_A", "1:B") - - // parses export keyword - parseAndCompare(t, "export OPTION_A=2", "OPTION_A", "2") - parseAndCompare(t, `export OPTION_B='\n'`, "OPTION_B", "\n") - - // it 'expands newlines in quoted strings' do - // expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz") - parseAndCompare(t, `FOO="bar\nbaz"`, "FOO", "bar\nbaz") - - // it 'parses varibales with "." in the name' do - // expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar') - parseAndCompare(t, "FOO.BAR=foobar", "FOO.BAR", "foobar") - - // it 'parses varibales with several "=" in the value' do - // expect(env('FOO=foobar=')).to eql('FOO' => 'foobar=') - parseAndCompare(t, "FOO=foobar=", "FOO", "foobar=") - - // it 'strips unquoted values' do - // expect(env('foo=bar ')).to eql('foo' => 'bar') # not 'bar ' - parseAndCompare(t, "FOO=bar ", "FOO", "bar") - - // it 'ignores inline comments' do - // expect(env("foo=bar # this is foo")).to eql('foo' => 'bar') - parseAndCompare(t, "FOO=bar # this is foo", "FOO", "bar") - - // it 'allows # in quoted value' do - // expect(env('foo="bar#baz" # comment')).to eql('foo' => 'bar#baz') - parseAndCompare(t, `FOO="bar#baz" # comment`, "FOO", "bar#baz") - parseAndCompare(t, "FOO='bar#baz' # comment", "FOO", "bar#baz") - parseAndCompare(t, `FOO="bar#baz#bang" # comment`, "FOO", "bar#baz#bang") - - // it 'parses # in quoted values' do - // expect(env('foo="ba#r"')).to eql('foo' => 'ba#r') - // expect(env("foo='ba#r'")).to eql('foo' => 'ba#r') - parseAndCompare(t, `FOO="ba#r"`, "FOO", "ba#r") - parseAndCompare(t, "FOO='ba#r'", "FOO", "ba#r") - - //newlines and backslashes should be escaped - parseAndCompare(t, `FOO="bar\n\ b\az"`, "FOO", "bar\n baz") - parseAndCompare(t, `FOO="bar\\\n\ b\az"`, "FOO", "bar\\\n baz") - parseAndCompare(t, `FOO="bar\\r\ b\az"`, "FOO", "bar\\r baz") - - parseAndCompare(t, `="value"`, "", "value") - parseAndCompare(t, `KEY="`, "KEY", "\"") - parseAndCompare(t, `KEY="value`, "KEY", "\"value") - - // it 'throws an error if line format is incorrect' do - // expect{env('lol$wut')}.to raise_error(Dotenv::FormatError) - badlyFormattedLine := "lol$wut" - _, _, err := parseLine(badlyFormattedLine) - if err == nil { - t.Errorf("Expected \"%v\" to return error, but it didn't", badlyFormattedLine) - } -} - -func TestLinesToIgnore(t *testing.T) { - // it 'ignores empty lines' do - // expect(env("\n \t \nfoo=bar\n \nfizz=buzz")).to eql('foo' => 'bar', 'fizz' => 'buzz') - if !isIgnoredLine("\n") { - t.Error("Line with nothing but line break wasn't ignored") - } - - if !isIgnoredLine("\t\t ") { - t.Error("Line full of whitespace wasn't ignored") - } - - // it 'ignores comment lines' do - // expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql('foo' => 'bar') - if !isIgnoredLine("# comment") { - t.Error("Comment wasn't ignored") - } - - if !isIgnoredLine("\t#comment") { - t.Error("Indented comment wasn't ignored") - } - - // make sure we're not getting false positives - if isIgnoredLine(`export OPTION_B='\n'`) { - t.Error("ignoring a perfectly valid line to parse") - } -} - -func TestErrorReadDirectory(t *testing.T) { - envFileName := "fixtures/" - envMap, err := Read(envFileName) - - if err == nil { - t.Errorf("Expected error, got %v", envMap) - } -} - -func TestErrorParsing(t *testing.T) { - envFileName := "fixtures/invalid1.env" - envMap, err := Read(envFileName) - if err == nil { - t.Errorf("Expected error, got %v", envMap) - } -} - -func TestWrite(t *testing.T) { - writeAndCompare := func(env string, expected string) { - envMap, _ := Unmarshal(env) - actual, _ := Marshal(envMap) - if expected != actual { - t.Errorf("Expected '%v' (%v) to write as '%v', got '%v' instead.", env, envMap, expected, actual) - } - } - //just test some single lines to show the general idea - //TestRoundtrip makes most of the good assertions - - //values are always double-quoted - writeAndCompare(`key=value`, `key="value"`) - //double-quotes are escaped - writeAndCompare(`key=va"lu"e`, `key="va\"lu\"e"`) - //but single quotes are left alone - writeAndCompare(`key=va'lu'e`, `key="va'lu'e"`) - // newlines, backslashes, and some other special chars are escaped - writeAndCompare(`foo="$ba\n\r\\r!"`, `foo="\$ba\n\r\\r\!"`) - // lines should be sorted - writeAndCompare("foo=bar\nbaz=buzz", "baz=\"buzz\"\nfoo=\"bar\"") -} - -func TestRoundtrip(t *testing.T) { - fixtures := []string{"equals.env", "exported.env", "plain.env", "quoted.env"} - for _, fixture := range fixtures { - fixtureFilename := fmt.Sprintf("fixtures/%s", fixture) - env, err := readFile(fixtureFilename) - if err != nil { - t.Errorf("Expected '%s' to read without error (%v)", fixtureFilename, err) - } - rep, err := Marshal(env) - if err != nil { - t.Errorf("Expected '%s' to Marshal (%v)", fixtureFilename, err) - } - roundtripped, err := Unmarshal(rep) - if err != nil { - t.Errorf("Expected '%s' to Mashal and Unmarshal (%v)", fixtureFilename, err) - } - if !reflect.DeepEqual(env, roundtripped) { - t.Errorf("Expected '%s' to roundtrip as '%v', got '%v' instead", fixtureFilename, env, roundtripped) - } - } -} diff --git a/plugins/config/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/config/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/config/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/config/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/config/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/config/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/config/vendor/github.com/ryanuber/columnize/README.md b/plugins/config/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index 9a583db8d..000000000 --- a/plugins/config/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,71 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -config.NoTrim = false -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output -* `NoTrim` is a boolean used to disable the automatic trimming of input values - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/config/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/config/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 527c1d1b3..000000000 --- a/plugins/config/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,191 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields. - Empty string - - // NoTrim disables automatic trimming of inputs. - NoTrim bool -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - NoTrim: false, - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - // Return quickly if either side was nil - if a == nil { - return b - } - if b == nil { - return a - } - - var result Config = *a - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - if b.NoTrim { - result.NoTrim = true - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - separated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(separated)) - for i, field := range separated { - value := field - if !config.NoTrim { - value = strings.TrimSpace(field) - } - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/config/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/config/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index a3194c3d0..000000000 --- a/plugins/config/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,340 +0,0 @@ -package columnize - -import ( - "fmt" - "reflect" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestVariedInputSpacing_NoTrim(t *testing.T) { - input := []string{ - "Column A|Column B|Column C", - "x|y| z", - } - - config := DefaultConfig() - config.NoTrim = true - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - for _, tc := range []struct { - desc string - configA *Config - configB *Config - expect *Config - }{ - { - "merges b over a", - &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"}, - &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"}, - &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"}, - }, - { - "merges only non-empty config values", - &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"}, - &Config{Delim: "b", Prefix: "b"}, - &Config{Delim: "b", Glue: "a", Prefix: "b", Empty: "a"}, - }, - { - "takes b if a is nil", - nil, - &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"}, - &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"}, - }, - { - "takes a if b is nil", - &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"}, - nil, - &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"}, - }, - } { - t.Run(tc.desc, func(t *testing.T) { - m := MergeConfig(tc.configA, tc.configB) - if !reflect.DeepEqual(m, tc.expect) { - t.Fatalf("\nexpect:\n%#v\n\nactual:\n%#v", tc.expect, m) - } - }) - } -} diff --git a/plugins/network/glide.yaml b/plugins/network/glide.yaml deleted file mode 100644 index a720d6c11..000000000 --- a/plugins/network/glide.yaml +++ /dev/null @@ -1,4 +0,0 @@ -package: . -import: -- package: github.com/codeskyblue/go-sh -- package: github.com/ryanuber/columnize diff --git a/plugins/network/go.mod b/plugins/network/go.mod new file mode 100644 index 000000000..f0dc09324 --- /dev/null +++ b/plugins/network/go.mod @@ -0,0 +1,13 @@ +module github.com/dokku/dokku/plugins/network + +go 1.14 + +require ( + github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000 +) + +replace github.com/dokku/dokku/plugins/common => ../common +replace github.com/dokku/dokku/plugins/config => ../config diff --git a/plugins/network/go.sum b/plugins/network/go.sum new file mode 100644 index 000000000..6d8e1933b --- /dev/null +++ b/plugins/network/go.sum @@ -0,0 +1,47 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/network/src/commands/commands.go b/plugins/network/src/commands/commands.go index 45c2167a9..7160ceab9 100644 --- a/plugins/network/src/commands/commands.go +++ b/plugins/network/src/commands/commands.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - columnize "github.com/ryanuber/columnize" ) const ( @@ -60,11 +59,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/network/src/glide.lock b/plugins/network/src/glide.lock deleted file mode 100644 index fe4a98f07..000000000 --- a/plugins/network/src/glide.lock +++ /dev/null @@ -1,6 +0,0 @@ -hash: 1ddab5de41d1514c2722bd7e24758ad4b60bf6956eb5b9b925fa071a1427f149 -updated: 2017-01-03T17:16:50.97156327-08:00 -imports: -- name: github.com/ryanuber/columnize - version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360 -testImports: [] diff --git a/plugins/network/src/glide.yaml b/plugins/network/src/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/network/src/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/network/src/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/network/src/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/network/src/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/network/src/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/network/src/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/network/src/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/network/src/vendor/github.com/ryanuber/columnize/README.md b/plugins/network/src/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/network/src/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/network/src/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/network/src/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/network/src/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/network/src/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/network/src/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/network/src/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/network/vendor/github.com/codegangsta/inject/.gitignore b/plugins/network/vendor/github.com/codegangsta/inject/.gitignore deleted file mode 100644 index df3df8a90..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -inject -inject.test diff --git a/plugins/network/vendor/github.com/codegangsta/inject/LICENSE b/plugins/network/vendor/github.com/codegangsta/inject/LICENSE deleted file mode 100644 index eb68a0e05..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Jeremy Saenz - -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/plugins/network/vendor/github.com/codegangsta/inject/README.md b/plugins/network/vendor/github.com/codegangsta/inject/README.md deleted file mode 100644 index 679abe01a..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# inject --- - import "github.com/codegangsta/inject" - -Package inject provides utilities for mapping and injecting dependencies in -various ways. - -Language Translations: -* [简体中文](translations/README_zh_cn.md) - -## Usage - -#### func InterfaceOf - -```go -func InterfaceOf(value interface{}) reflect.Type -``` -InterfaceOf dereferences a pointer to an Interface type. It panics if value is -not an pointer to an interface. - -#### type Applicator - -```go -type Applicator interface { - // Maps dependencies in the Type map to each field in the struct - // that is tagged with 'inject'. Returns an error if the injection - // fails. - Apply(interface{}) error -} -``` - -Applicator represents an interface for mapping dependencies to a struct. - -#### type Injector - -```go -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent sets the parent of the injector. If the injector cannot find a - // dependency in its Type map it will check its parent before returning an - // error. - SetParent(Injector) -} -``` - -Injector represents an interface for mapping and injecting dependencies into -structs and function arguments. - -#### func New - -```go -func New() Injector -``` -New returns a new Injector. - -#### type Invoker - -```go -type Invoker interface { - // Invoke attempts to call the interface{} provided as a function, - // providing dependencies for function arguments based on Type. Returns - // a slice of reflect.Value representing the returned values of the function. - // Returns an error if the injection fails. - Invoke(interface{}) ([]reflect.Value, error) -} -``` - -Invoker represents an interface for calling functions via reflection. - -#### type TypeMapper - -```go -type TypeMapper interface { - // Maps the interface{} value based on its immediate type from reflect.TypeOf. - Map(interface{}) TypeMapper - // Maps the interface{} value based on the pointer of an Interface provided. - // This is really only useful for mapping a value as an interface, as interfaces - // cannot at this time be referenced directly without a pointer. - MapTo(interface{}, interface{}) TypeMapper - // Provides a possibility to directly insert a mapping based on type and value. - // This makes it possible to directly map type arguments not possible to instantiate - // with reflect like unidirectional channels. - Set(reflect.Type, reflect.Value) TypeMapper - // Returns the Value that is mapped to the current type. Returns a zeroed Value if - // the Type has not been mapped. - Get(reflect.Type) reflect.Value -} -``` - -TypeMapper represents an interface for mapping interface{} values based on type. diff --git a/plugins/network/vendor/github.com/codegangsta/inject/inject.go b/plugins/network/vendor/github.com/codegangsta/inject/inject.go deleted file mode 100644 index 3ff713c8a..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/inject.go +++ /dev/null @@ -1,187 +0,0 @@ -// Package inject provides utilities for mapping and injecting dependencies in various ways. -package inject - -import ( - "fmt" - "reflect" -) - -// Injector represents an interface for mapping and injecting dependencies into structs -// and function arguments. -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent sets the parent of the injector. If the injector cannot find a - // dependency in its Type map it will check its parent before returning an - // error. - SetParent(Injector) -} - -// Applicator represents an interface for mapping dependencies to a struct. -type Applicator interface { - // Maps dependencies in the Type map to each field in the struct - // that is tagged with 'inject'. Returns an error if the injection - // fails. - Apply(interface{}) error -} - -// Invoker represents an interface for calling functions via reflection. -type Invoker interface { - // Invoke attempts to call the interface{} provided as a function, - // providing dependencies for function arguments based on Type. Returns - // a slice of reflect.Value representing the returned values of the function. - // Returns an error if the injection fails. - Invoke(interface{}) ([]reflect.Value, error) -} - -// TypeMapper represents an interface for mapping interface{} values based on type. -type TypeMapper interface { - // Maps the interface{} value based on its immediate type from reflect.TypeOf. - Map(interface{}) TypeMapper - // Maps the interface{} value based on the pointer of an Interface provided. - // This is really only useful for mapping a value as an interface, as interfaces - // cannot at this time be referenced directly without a pointer. - MapTo(interface{}, interface{}) TypeMapper - // Provides a possibility to directly insert a mapping based on type and value. - // This makes it possible to directly map type arguments not possible to instantiate - // with reflect like unidirectional channels. - Set(reflect.Type, reflect.Value) TypeMapper - // Returns the Value that is mapped to the current type. Returns a zeroed Value if - // the Type has not been mapped. - Get(reflect.Type) reflect.Value -} - -type injector struct { - values map[reflect.Type]reflect.Value - parent Injector -} - -// InterfaceOf dereferences a pointer to an Interface type. -// It panics if value is not an pointer to an interface. -func InterfaceOf(value interface{}) reflect.Type { - t := reflect.TypeOf(value) - - for t.Kind() == reflect.Ptr { - t = t.Elem() - } - - if t.Kind() != reflect.Interface { - panic("Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)") - } - - return t -} - -// New returns a new Injector. -func New() Injector { - return &injector{ - values: make(map[reflect.Type]reflect.Value), - } -} - -// Invoke attempts to call the interface{} provided as a function, -// providing dependencies for function arguments based on Type. -// Returns a slice of reflect.Value representing the returned values of the function. -// Returns an error if the injection fails. -// It panics if f is not a function -func (inj *injector) Invoke(f interface{}) ([]reflect.Value, error) { - t := reflect.TypeOf(f) - - var in = make([]reflect.Value, t.NumIn()) //Panic if t is not kind of Func - for i := 0; i < t.NumIn(); i++ { - argType := t.In(i) - val := inj.Get(argType) - if !val.IsValid() { - return nil, fmt.Errorf("Value not found for type %v", argType) - } - - in[i] = val - } - - return reflect.ValueOf(f).Call(in), nil -} - -// Maps dependencies in the Type map to each field in the struct -// that is tagged with 'inject'. -// Returns an error if the injection fails. -func (inj *injector) Apply(val interface{}) error { - v := reflect.ValueOf(val) - - for v.Kind() == reflect.Ptr { - v = v.Elem() - } - - if v.Kind() != reflect.Struct { - return nil // Should not panic here ? - } - - t := v.Type() - - for i := 0; i < v.NumField(); i++ { - f := v.Field(i) - structField := t.Field(i) - if f.CanSet() && (structField.Tag == "inject" || structField.Tag.Get("inject") != "") { - ft := f.Type() - v := inj.Get(ft) - if !v.IsValid() { - return fmt.Errorf("Value not found for type %v", ft) - } - - f.Set(v) - } - - } - - return nil -} - -// Maps the concrete value of val to its dynamic type using reflect.TypeOf, -// It returns the TypeMapper registered in. -func (i *injector) Map(val interface{}) TypeMapper { - i.values[reflect.TypeOf(val)] = reflect.ValueOf(val) - return i -} - -func (i *injector) MapTo(val interface{}, ifacePtr interface{}) TypeMapper { - i.values[InterfaceOf(ifacePtr)] = reflect.ValueOf(val) - return i -} - -// Maps the given reflect.Type to the given reflect.Value and returns -// the Typemapper the mapping has been registered in. -func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper { - i.values[typ] = val - return i -} - -func (i *injector) Get(t reflect.Type) reflect.Value { - val := i.values[t] - - if val.IsValid() { - return val - } - - // no concrete types found, try to find implementors - // if t is an interface - if t.Kind() == reflect.Interface { - for k, v := range i.values { - if k.Implements(t) { - val = v - break - } - } - } - - // Still no type found, try to look it up on the parent - if !val.IsValid() && i.parent != nil { - val = i.parent.Get(t) - } - - return val - -} - -func (i *injector) SetParent(parent Injector) { - i.parent = parent -} diff --git a/plugins/network/vendor/github.com/codegangsta/inject/inject_test.go b/plugins/network/vendor/github.com/codegangsta/inject/inject_test.go deleted file mode 100644 index eb94471d3..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/inject_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package inject_test - -import ( - "fmt" - "github.com/codegangsta/inject" - "reflect" - "testing" -) - -type SpecialString interface { -} - -type TestStruct struct { - Dep1 string `inject:"t" json:"-"` - Dep2 SpecialString `inject` - Dep3 string -} - -type Greeter struct { - Name string -} - -func (g *Greeter) String() string { - return "Hello, My name is" + g.Name -} - -/* Test Helpers */ -func expect(t *testing.T, a interface{}, b interface{}) { - if a != b { - t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -} - -func refute(t *testing.T, a interface{}, b interface{}) { - if a == b { - t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -} - -func Test_InjectorInvoke(t *testing.T) { - injector := inject.New() - expect(t, injector == nil, false) - - dep := "some dependency" - injector.Map(dep) - dep2 := "another dep" - injector.MapTo(dep2, (*SpecialString)(nil)) - dep3 := make(chan *SpecialString) - dep4 := make(chan *SpecialString) - typRecv := reflect.ChanOf(reflect.RecvDir, reflect.TypeOf(dep3).Elem()) - typSend := reflect.ChanOf(reflect.SendDir, reflect.TypeOf(dep4).Elem()) - injector.Set(typRecv, reflect.ValueOf(dep3)) - injector.Set(typSend, reflect.ValueOf(dep4)) - - _, err := injector.Invoke(func(d1 string, d2 SpecialString, d3 <-chan *SpecialString, d4 chan<- *SpecialString) { - expect(t, d1, dep) - expect(t, d2, dep2) - expect(t, reflect.TypeOf(d3).Elem(), reflect.TypeOf(dep3).Elem()) - expect(t, reflect.TypeOf(d4).Elem(), reflect.TypeOf(dep4).Elem()) - expect(t, reflect.TypeOf(d3).ChanDir(), reflect.RecvDir) - expect(t, reflect.TypeOf(d4).ChanDir(), reflect.SendDir) - }) - - expect(t, err, nil) -} - -func Test_InjectorInvokeReturnValues(t *testing.T) { - injector := inject.New() - expect(t, injector == nil, false) - - dep := "some dependency" - injector.Map(dep) - dep2 := "another dep" - injector.MapTo(dep2, (*SpecialString)(nil)) - - result, err := injector.Invoke(func(d1 string, d2 SpecialString) string { - expect(t, d1, dep) - expect(t, d2, dep2) - return "Hello world" - }) - - expect(t, result[0].String(), "Hello world") - expect(t, err, nil) -} - -func Test_InjectorApply(t *testing.T) { - injector := inject.New() - - injector.Map("a dep").MapTo("another dep", (*SpecialString)(nil)) - - s := TestStruct{} - err := injector.Apply(&s) - expect(t, err, nil) - - expect(t, s.Dep1, "a dep") - expect(t, s.Dep2, "another dep") - expect(t, s.Dep3, "") -} - -func Test_InterfaceOf(t *testing.T) { - iType := inject.InterfaceOf((*SpecialString)(nil)) - expect(t, iType.Kind(), reflect.Interface) - - iType = inject.InterfaceOf((**SpecialString)(nil)) - expect(t, iType.Kind(), reflect.Interface) - - // Expecting nil - defer func() { - rec := recover() - refute(t, rec, nil) - }() - iType = inject.InterfaceOf((*testing.T)(nil)) -} - -func Test_InjectorSet(t *testing.T) { - injector := inject.New() - typ := reflect.TypeOf("string") - typSend := reflect.ChanOf(reflect.SendDir, typ) - typRecv := reflect.ChanOf(reflect.RecvDir, typ) - - // instantiating unidirectional channels is not possible using reflect - // http://golang.org/src/pkg/reflect/value.go?s=60463:60504#L2064 - chanRecv := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, typ), 0) - chanSend := reflect.MakeChan(reflect.ChanOf(reflect.BothDir, typ), 0) - - injector.Set(typSend, chanSend) - injector.Set(typRecv, chanRecv) - - expect(t, injector.Get(typSend).IsValid(), true) - expect(t, injector.Get(typRecv).IsValid(), true) - expect(t, injector.Get(chanSend.Type()).IsValid(), false) -} - -func Test_InjectorGet(t *testing.T) { - injector := inject.New() - - injector.Map("some dependency") - - expect(t, injector.Get(reflect.TypeOf("string")).IsValid(), true) - expect(t, injector.Get(reflect.TypeOf(11)).IsValid(), false) -} - -func Test_InjectorSetParent(t *testing.T) { - injector := inject.New() - injector.MapTo("another dep", (*SpecialString)(nil)) - - injector2 := inject.New() - injector2.SetParent(injector) - - expect(t, injector2.Get(inject.InterfaceOf((*SpecialString)(nil))).IsValid(), true) -} - -func TestInjectImplementors(t *testing.T) { - injector := inject.New() - g := &Greeter{"Jeremy"} - injector.Map(g) - - expect(t, injector.Get(inject.InterfaceOf((*fmt.Stringer)(nil))).IsValid(), true) -} diff --git a/plugins/network/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md b/plugins/network/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md deleted file mode 100644 index 0ac3d3f55..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/translations/README_zh_cn.md +++ /dev/null @@ -1,85 +0,0 @@ -# inject --- - import "github.com/codegangsta/inject" - -inject包提供了多种对实体的映射和依赖注入方式。 - -## 用法 - -#### func InterfaceOf - -```go -func InterfaceOf(value interface{}) reflect.Type -``` -函数InterfaceOf返回指向接口类型的指针。如果传入的value值不是指向接口的指针,将抛出一个panic异常。 - -#### type Applicator - -```go -type Applicator interface { - // 在Type map中维持对结构体中每个域的引用并用'inject'来标记 - // 如果注入失败将会返回一个error. - Apply(interface{}) error -} -``` - -Applicator接口表示到结构体的依赖映射关系。 - -#### type Injector - -```go -type Injector interface { - Applicator - Invoker - TypeMapper - // SetParent用来设置父injector. 如果在当前injector的Type map中找不到依赖, - // 将会继续从它的父injector中找,直到返回error. - SetParent(Injector) -} -``` - -Injector接口表示对结构体、函数参数的映射和依赖注入。 - -#### func New - -```go -func New() Injector -``` -New创建并返回一个Injector. - -#### type Invoker - -```go -type Invoker interface { - // Invoke尝试将interface{}作为一个函数来调用,并基于Type为函数提供参数。 - // 它将返回reflect.Value的切片,其中存放原函数的返回值。 - // 如果注入失败则返回error. - Invoke(interface{}) ([]reflect.Value, error) -} -``` - -Invoker接口表示通过反射进行函数调用。 - -#### type TypeMapper - -```go -type TypeMapper interface { - // 基于调用reflect.TypeOf得到的类型映射interface{}的值。 - Map(interface{}) TypeMapper - // 基于提供的接口的指针映射interface{}的值。 - // 该函数仅用来将一个值映射为接口,因为接口无法不通过指针而直接引用到。 - MapTo(interface{}, interface{}) TypeMapper - // 为直接插入基于类型和值的map提供一种可能性。 - // 它使得这一类直接映射成为可能:无法通过反射直接实例化的类型参数,如单向管道。 - Set(reflect.Type, reflect.Value) TypeMapper - // 返回映射到当前类型的Value. 如果Type没被映射,将返回对应的零值。 - Get(reflect.Type) reflect.Value -} -``` - -TypeMapper接口用来表示基于类型到接口值的映射。 - - -## 译者 - -张强 (qqbunny@yeah.net) \ No newline at end of file diff --git a/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh b/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh deleted file mode 100644 index 3cb21111c..000000000 --- a/plugins/network/vendor/github.com/codegangsta/inject/update_readme.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -go get github.com/robertkrimen/godocdown/godocdown -godocdown >README.md diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/LICENSE b/plugins/network/vendor/github.com/codeskyblue/go-sh/LICENSE deleted file mode 100644 index e06d20818..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/OLD_README.md b/plugins/network/vendor/github.com/codeskyblue/go-sh/OLD_README.md deleted file mode 100644 index 7e899402d..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/OLD_README.md +++ /dev/null @@ -1,69 +0,0 @@ -## OLD README -First give you a full example, I will explain every command below. - - session := sh.NewSession() - session.Env["PATH"] = "/usr/bin:/bin" - session.Stdout = os.Stdout - session.Stderr = os.Stderr - session.Alias("ll", "ls", "-l") - session.ShowCMD = true // enable for debug - var err error - err = session.Call("ll", "/") - if err != nil { - log.Fatal(err) - } - ret, err := session.Capture("pwd", sh.Dir("/home")) # wraper of session.Call - if err != nil { - log.Fatal(err) - } - # ret is "/home\n" - fmt.Println(ret) - -create a new Session - - session := sh.NewSession() - -use alias like this - - session.Alias("ll", "ls", "-l") # like alias ll='ls -l' - -set current env like this - - session.Env["BUILD_ID"] = "123" # like export BUILD_ID=123 - -set current directory - - session.Set(sh.Dir("/")) # like cd / - -pipe is also supported - - session.Command("echo", "hello\tworld").Command("cut", "-f2") - // output should be "world" - session.Run() - -test, the build in command support - - session.Test("d", "dir") // test dir - session.Test("f", "file) // test regular file - -with `Alias Env Set Call Capture Command` a shell scripts can be easily converted into golang program. below is a shell script. - - #!/bin/bash - - # - export PATH=/usr/bin:/bin - alias ll='ls -l' - cd /usr - if test -d "local" - then - ll local | awk '{print $1, $NF}' - fi - -convert to golang, will be - - s := sh.NewSession() - s.Env["PATH"] = "/usr/bin:/bin" - s.Set(sh.Dir("/usr")) - s.Alias("ll", "ls", "-l") - if s.Test("d", "local") { - s.Command("ll", "local").Command("awk", "{print $1, $NF}").Run() - } diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/README.md b/plugins/network/vendor/github.com/codeskyblue/go-sh/README.md deleted file mode 100644 index 28614708d..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/README.md +++ /dev/null @@ -1,85 +0,0 @@ -## go-sh -[![wercker status](https://app.wercker.com/status/009acbd4f00ccc6de7e2554e12a50d84/s "wercker status")](https://app.wercker.com/project/bykey/009acbd4f00ccc6de7e2554e12a50d84) -[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/codeskyblue/go-sh) - -*If you depend on the old api, see tag: v.0.1* - -install: `go get github.com/codeskyblue/go-sh` - -Pipe Example: - - package main - - import "github.com/codeskyblue/go-sh" - - func main() { - sh.Command("echo", "hello\tworld").Command("cut", "-f2").Run() - } - -Because I like os/exec, `go-sh` is very much modelled after it. However, `go-sh` provides a better experience. - -These are some of its features: - -* keep the variable environment (e.g. export) -* alias support (e.g. alias in shell) -* remember current dir -* pipe command -* shell build-in commands echo & test -* timeout support - -Examples are important: - - sh: echo hello - go: sh.Command("echo", "hello").Run() - - sh: export BUILD_ID=123 - go: s = sh.NewSession().SetEnv("BUILD_ID", "123") - - sh: alias ll='ls -l' - go: s = sh.NewSession().Alias('ll', 'ls', '-l') - - sh: (cd /; pwd) - go: sh.Command("pwd", sh.Dir("/")).Run() - - sh: test -d data || mkdir data - go: if ! sh.Test("dir", "data") { sh.Command("mkdir", "data").Run() } - - sh: cat first second | awk '{print $1}' - go: sh.Command("cat", "first", "second").Command("awk", "{print $1}").Run() - - sh: count=$(echo "one two three" | wc -w) - go: count, err := sh.Echo("one two three").Command("wc", "-w").Output() - - sh(in ubuntu): timeout 1s sleep 3 - go: c := sh.Command("sleep", "3"); c.Start(); c.WaitTimeout(time.Second) # default SIGKILL - go: out, err := sh.Command("sleep", "3").SetTimeout(time.Second).Output() # set session timeout and get output) - - sh: echo hello | cat - go: out, err := sh.Command("cat").SetInput("hello").Output() - - sh: cat # read from stdin - go: out, err := sh.Command("cat").SetStdin(os.Stdin).Output() - -If you need to keep env and dir, it is better to create a session - - session := sh.NewSession() - session.SetEnv("BUILD_ID", "123") - session.SetDir("/") - # then call cmd - session.Command("echo", "hello").Run() - # set ShowCMD to true for easily debug - session.ShowCMD = true - -for more information, it better to see docs. -[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/codeskyblue/go-sh) - -### contribute -If you love this project, starring it will encourage the coder. Pull requests are welcome. - -support the author: [alipay](https://me.alipay.com/goskyblue) - -### thanks -this project is based on . thanks for the author. - -# the reason to use Go shell -Sometimes we need to write shell scripts, but shell scripts are not good at working cross platform, Go, on the other hand, is good at that. Is there a good way to use Go to write shell like scripts? Using go-sh we can do this now. diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/example1.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/example/example1.go deleted file mode 100644 index cdc7f6c39..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/example1.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "fmt" - "log" - - "github.com/codeskyblue/go-sh" -) - -func main() { - sh.Command("echo", "hello").Run() - out, err := sh.Command("echo", "hello").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println("output is", string(out)) - - var a int - sh.Command("echo", "2").UnmarshalJSON(&a) - fmt.Println("a =", a) - - s := sh.NewSession() - s.Alias("hi", "echo", "hi") - s.Command("hi", "boy").Run() - - fmt.Print("pwd = ") - s.Command("pwd", sh.Dir("/")).Run() - - if !sh.Test("dir", "data") { - sh.Command("echo", "mkdir", "data").Run() - } - - sh.Command("echo", "hello", "world"). - Command("awk", `{print "second arg is "$2}`).Run() - s.ShowCMD = true - s.Command("echo", "hello", "world"). - Command("awk", `{print "second arg is "$2}`).Run() - - s.SetEnv("BUILD_ID", "123").Command("bash", "-c", "echo $BUILD_ID").Run() - s.Command("bash", "-c", "echo current shell is $SHELL").Run() -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/less/less.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/example/less/less.go deleted file mode 100644 index ffced2e81..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/less/less.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/codeskyblue/go-sh" - -func main() { - sh.Command("less", "less.go").Run() -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go deleted file mode 100644 index b7ecd3bed..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/tail/tailf.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "flag" - "fmt" - - "github.com/codeskyblue/go-sh" -) - -func main() { - flag.Parse() - if flag.NArg() != 1 { - fmt.Println("Usage: PROGRAM ") - return - } - sh.Command("tail", "-f", flag.Arg(0)).Run() -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go deleted file mode 100644 index 852908a47..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/example/timeout/timeout.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "fmt" - "time" - - sh "github.com/codeskyblue/go-sh" -) - -func main() { - c := sh.Command("sleep", "3") - c.Start() - err := c.WaitTimeout(time.Second * 1) - if err != nil { - fmt.Printf("timeout should happend: %v\n", err) - } - // timeout should be a session - out, err := sh.Command("sleep", "2").SetTimeout(time.Second).Output() - fmt.Printf("output:(%s), err(%v)\n", string(out), err) - - out, err = sh.Command("echo", "hello").SetTimeout(time.Second).Output() - fmt.Printf("output:(%s), err(%v)\n", string(out), err) -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/example_test.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/example_test.go deleted file mode 100644 index 5abfed64d..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/example_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package sh_test - -import ( - "fmt" - - "github.com/codeskyblue/go-sh" -) - -func ExampleCommand() { - out, err := sh.Command("echo", "hello").Output() - fmt.Println(string(out), err) -} - -func ExampleCommandPipe() { - out, err := sh.Command("echo", "-n", "hi").Command("wc", "-c").Output() - fmt.Println(string(out), err) -} - -func ExampleCommandSetDir() { - out, err := sh.Command("pwd", sh.Dir("/")).Output() - fmt.Println(string(out), err) -} - -func ExampleTest() { - if sh.Test("dir", "mydir") { - fmt.Println("mydir exists") - } -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/pipe.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/pipe.go deleted file mode 100644 index c35f4e2a0..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/pipe.go +++ /dev/null @@ -1,148 +0,0 @@ -package sh - -import ( - "bytes" - "encoding/json" - "encoding/xml" - "errors" - "io" - "os" - "strings" - "syscall" - "time" -) - -var ErrExecTimeout = errors.New("execute timeout") - -// unmarshal shell output to decode json -func (s *Session) UnmarshalJSON(data interface{}) (err error) { - bufrw := bytes.NewBuffer(nil) - s.Stdout = bufrw - if err = s.Run(); err != nil { - return - } - return json.NewDecoder(bufrw).Decode(data) -} - -// unmarshal command output into xml -func (s *Session) UnmarshalXML(data interface{}) (err error) { - bufrw := bytes.NewBuffer(nil) - s.Stdout = bufrw - if err = s.Run(); err != nil { - return - } - return xml.NewDecoder(bufrw).Decode(data) -} - -// start command -func (s *Session) Start() (err error) { - s.started = true - var rd *io.PipeReader - var wr *io.PipeWriter - var length = len(s.cmds) - if s.ShowCMD { - var cmds = make([]string, 0, 4) - for _, cmd := range s.cmds { - cmds = append(cmds, strings.Join(cmd.Args, " ")) - } - s.writePrompt(strings.Join(cmds, " | ")) - } - for index, cmd := range s.cmds { - if index == 0 { - cmd.Stdin = s.Stdin - } else { - cmd.Stdin = rd - } - if index != length { - rd, wr = io.Pipe() // create pipe - cmd.Stdout = wr - cmd.Stderr = os.Stderr - } - if index == length-1 { - cmd.Stdout = s.Stdout - cmd.Stderr = s.Stderr - } - err = cmd.Start() - if err != nil { - return - } - } - return -} - -// Should be call after Start() -// only catch the last command error -func (s *Session) Wait() (err error) { - for _, cmd := range s.cmds { - err = cmd.Wait() - wr, ok := cmd.Stdout.(*io.PipeWriter) - if ok { - wr.Close() - } - } - return err -} - -func (s *Session) Kill(sig os.Signal) { - for _, cmd := range s.cmds { - if cmd.Process != nil { - cmd.Process.Signal(sig) - } - } -} - -func (s *Session) WaitTimeout(timeout time.Duration) (err error) { - select { - case <-time.After(timeout): - s.Kill(syscall.SIGKILL) - return ErrExecTimeout - case err = <-Go(s.Wait): - return err - } -} - -func Go(f func() error) chan error { - ch := make(chan error) - go func() { - ch <- f() - }() - return ch -} - -func (s *Session) Run() (err error) { - if err = s.Start(); err != nil { - return - } - if s.timeout != time.Duration(0) { - return s.WaitTimeout(s.timeout) - } - return s.Wait() -} - -func (s *Session) Output() (out []byte, err error) { - oldout := s.Stdout - defer func() { - s.Stdout = oldout - }() - stdout := bytes.NewBuffer(nil) - s.Stdout = stdout - err = s.Run() - out = stdout.Bytes() - return -} - -func (s *Session) CombinedOutput() (out []byte, err error) { - oldout := s.Stdout - olderr := s.Stderr - defer func() { - s.Stdout = oldout - s.Stderr = olderr - }() - stdout := bytes.NewBuffer(nil) - s.Stdout = stdout - s.Stderr = stdout - - err = s.Run() - out = stdout.Bytes() - return -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/pipe_test.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/pipe_test.go deleted file mode 100644 index 8d0e22c0c..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/pipe_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package sh - -import ( - "encoding/xml" - "io" - "os" - "os/exec" - "strings" - "testing" - "time" -) - -func TestUnmarshalJSON(t *testing.T) { - var a int - s := NewSession() - s.ShowCMD = true - err := s.Command("echo", []string{"1"}).UnmarshalJSON(&a) - if err != nil { - t.Error(err) - } - if a != 1 { - t.Errorf("expect a tobe 1, but got %d", a) - } -} - -func TestUnmarshalXML(t *testing.T) { - s := NewSession() - xmlSample := ` -` - type server struct { - XMLName xml.Name `xml:"server"` - Version string `xml:"version,attr"` - } - data := &server{} - s.Command("echo", xmlSample).UnmarshalXML(data) - if data.Version != "1" { - t.Error(data) - } -} - -func TestPipe(t *testing.T) { - s := NewSession() - s.ShowCMD = true - s.Call("echo", "hello") - err := s.Command("echo", "hi").Command("cat", "-n").Start() - if err != nil { - t.Error(err) - } - err = s.Wait() - if err != nil { - t.Error(err) - } - out, err := s.Command("echo", []string{"hello"}).Output() - if err != nil { - t.Error(err) - } - if string(out) != "hello\n" { - t.Error("capture wrong output:", out) - } - s.Command("echo", []string{"hello\tworld"}).Command("cut", []string{"-f2"}).Run() -} - -func TestPipeCommand(t *testing.T) { - c1 := exec.Command("echo", "good") - rd, wr := io.Pipe() - c1.Stdout = wr - c2 := exec.Command("cat", "-n") - c2.Stdout = os.Stdout - c2.Stdin = rd - c1.Start() - c2.Start() - - c1.Wait() - wc, ok := c1.Stdout.(io.WriteCloser) - if ok { - wc.Close() - } - c2.Wait() -} - -func TestPipeInput(t *testing.T) { - s := NewSession() - s.ShowCMD = true - s.SetInput("first line\nsecond line\n") - out, err := s.Command("grep", "second").Output() - if err != nil { - t.Error(err) - } - if string(out) != "second line\n" { - t.Error("capture wrong output:", out) - } -} - -func TestTimeout(t *testing.T) { - s := NewSession() - err := s.Command("sleep", "2").Start() - if err != nil { - t.Fatal(err) - } - err = s.WaitTimeout(time.Second) - if err != ErrExecTimeout { - t.Fatal(err) - } -} - -func TestSetTimeout(t *testing.T) { - s := NewSession() - s.SetTimeout(time.Second) - defer s.SetTimeout(0) - err := s.Command("sleep", "2").Run() - if err != ErrExecTimeout { - t.Fatal(err) - } -} - -func TestCombinedOutput(t *testing.T) { - s := NewSession() - bytes, err := s.Command("sh", "-c", "echo stderr >&2 ; echo stdout").CombinedOutput() - if err != nil { - t.Error(err) - } - stringOutput := string(bytes) - if !(strings.Contains(stringOutput, "stdout") && strings.Contains(stringOutput, "stderr")) { - t.Errorf("expect output from both output streams, got '%s'", strings.TrimSpace(stringOutput)) - } -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/sh.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/sh.go deleted file mode 100644 index 15f1b85d5..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/sh.go +++ /dev/null @@ -1,200 +0,0 @@ -/* -Package go-sh is intented to make shell call with golang more easily. -Some usage is more similar to os/exec, eg: Run(), Output(), Command(name, args...) - -But with these similar function, pipe is added in and this package also got shell-session support. - -Why I love golang so much, because the usage of golang is simple, but the power is unlimited. I want to make this pakcage got the sample style like golang. - - // just like os/exec - sh.Command("echo", "hello").Run() - - // support pipe - sh.Command("echo", "hello").Command("wc", "-c").Run() - - // create a session to store dir and env - sh.NewSession().SetDir("/").Command("pwd") - - // shell buildin command - "test" - sh.Test("dir", "mydir") - - // like shell call: (cd /; pwd) - sh.Command("pwd", sh.Dir("/")) same with sh.Command(sh.Dir("/"), "pwd") - - // output to json and xml easily - v := map[string] int {} - err = sh.Command("echo", `{"number": 1}`).UnmarshalJSON(&v) -*/ -package sh - -import ( - "fmt" - "io" - "os" - "os/exec" - "reflect" - "strings" - "time" - - "github.com/codegangsta/inject" -) - -type Dir string - -type Session struct { - inj inject.Injector - alias map[string][]string - cmds []*exec.Cmd - dir Dir - started bool - Env map[string]string - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer - ShowCMD bool // enable for debug - timeout time.Duration -} - -func (s *Session) writePrompt(args ...interface{}) { - var ps1 = fmt.Sprintf("[golang-sh]$") - args = append([]interface{}{ps1}, args...) - fmt.Fprintln(s.Stderr, args...) -} - -func NewSession() *Session { - env := make(map[string]string) - for _, key := range []string{"PATH"} { - env[key] = os.Getenv(key) - } - s := &Session{ - inj: inject.New(), - alias: make(map[string][]string), - dir: Dir(""), - Stdin: strings.NewReader(""), - Stdout: os.Stdout, - Stderr: os.Stderr, - Env: env, - } - return s -} - -func InteractiveSession() *Session { - s := NewSession() - s.SetStdin(os.Stdin) - return s -} - -func Command(name string, a ...interface{}) *Session { - s := NewSession() - return s.Command(name, a...) -} - -func Echo(in string) *Session { - s := NewSession() - return s.SetInput(in) -} - -func (s *Session) Alias(alias, cmd string, args ...string) { - v := []string{cmd} - v = append(v, args...) - s.alias[alias] = v -} - -func (s *Session) Command(name string, a ...interface{}) *Session { - var args = make([]string, 0) - var sType = reflect.TypeOf("") - - // init cmd, args, dir, envs - // if not init, program may panic - s.inj.Map(name).Map(args).Map(s.dir).Map(map[string]string{}) - for _, v := range a { - switch reflect.TypeOf(v) { - case sType: - args = append(args, v.(string)) - default: - s.inj.Map(v) - } - } - if len(args) != 0 { - s.inj.Map(args) - } - s.inj.Invoke(s.appendCmd) - return s -} - -// combine Command and Run -func (s *Session) Call(name string, a ...interface{}) error { - return s.Command(name, a...).Run() -} - -/* -func (s *Session) Exec(cmd string, args ...string) error { - return s.Call(cmd, args) -} -*/ - -func (s *Session) SetEnv(key, value string) *Session { - s.Env[key] = value - return s -} - -func (s *Session) SetDir(dir string) *Session { - s.dir = Dir(dir) - return s -} - -func (s *Session) SetInput(in string) *Session { - s.Stdin = strings.NewReader(in) - return s -} - -func (s *Session) SetStdin(r io.Reader) *Session { - s.Stdin = r - return s -} - -func (s *Session) SetTimeout(d time.Duration) *Session { - s.timeout = d - return s -} - -func newEnviron(env map[string]string, inherit bool) []string { //map[string]string { - environ := make([]string, 0, len(env)) - if inherit { - for _, line := range os.Environ() { - for k, _ := range env { - if strings.HasPrefix(line, k+"=") { - goto CONTINUE - } - } - environ = append(environ, line) - CONTINUE: - } - } - for k, v := range env { - environ = append(environ, k+"="+v) - } - return environ -} - -func (s *Session) appendCmd(cmd string, args []string, cwd Dir, env map[string]string) { - if s.started { - s.started = false - s.cmds = make([]*exec.Cmd, 0) - } - for k, v := range s.Env { - if _, ok := env[k]; !ok { - env[k] = v - } - } - environ := newEnviron(s.Env, true) // true: inherit sys-env - v, ok := s.alias[cmd] - if ok { - cmd = v[0] - args = append(v[1:], args...) - } - c := exec.Command(cmd, args...) - c.Env = environ - c.Dir = string(cwd) - s.cmds = append(s.cmds, c) -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/sh_test.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/sh_test.go deleted file mode 100644 index be5c27998..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/sh_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package sh - -import ( - "fmt" - "log" - "runtime" - "strings" - "testing" -) - -func TestAlias(t *testing.T) { - s := NewSession() - s.Alias("gr", "echo", "hi") - out, err := s.Command("gr", "sky").Output() - if err != nil { - t.Error(err) - } - if string(out) != "hi sky\n" { - t.Errorf("expect 'hi sky' but got:%s", string(out)) - } -} - -func ExampleSession_Command() { - s := NewSession() - out, err := s.Command("echo", "hello").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: hello -} - -func ExampleSession_Command_pipe() { - s := NewSession() - out, err := s.Command("echo", "hello", "world").Command("awk", "{print $2}").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: world -} - -func ExampleSession_Alias() { - s := NewSession() - s.Alias("alias_echo_hello", "echo", "hello") - out, err := s.Command("alias_echo_hello", "world").Output() - if err != nil { - log.Fatal(err) - } - fmt.Println(string(out)) - // Output: hello world -} - -func TestEcho(t *testing.T) { - out, err := Echo("one two three").Command("wc", "-w").Output() - if err != nil { - t.Error(err) - } - if strings.TrimSpace(string(out)) != "3" { - t.Errorf("expect '3' but got:%s", string(out)) - } -} - -func TestSession(t *testing.T) { - if runtime.GOOS == "windows" { - t.Log("ignore test on windows") - return - } - session := NewSession() - session.ShowCMD = true - err := session.Call("pwd") - if err != nil { - t.Error(err) - } - out, err := session.SetDir("/").Command("pwd").Output() - if err != nil { - t.Error(err) - } - if string(out) != "/\n" { - t.Errorf("expect /, but got %s", string(out)) - } -} - -/* - #!/bin/bash - - # - export PATH=/usr/bin:/bin - alias ll='ls -l' - cd /usr - if test -d "local" - then - ll local | awk '{print $1, $NF}' | grep bin - fi -*/ -func Example(t *testing.T) { - s := NewSession() - //s.ShowCMD = true - s.Env["PATH"] = "/usr/bin:/bin" - s.SetDir("/bin") - s.Alias("ll", "ls", "-l") - - if s.Test("d", "local") { - //s.Command("ll", []string{"local"}).Command("awk", []string{"{print $1, $NF}"}).Command("grep", []string{"bin"}).Run() - s.Command("ll", "local").Command("awk", "{print $1, $NF}").Command("grep", "bin").Run() - } -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/test.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/test.go deleted file mode 100644 index b9d310527..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/test.go +++ /dev/null @@ -1,64 +0,0 @@ -package sh - -import ( - "os" - "path/filepath" -) - -func filetest(name string, modemask os.FileMode) (match bool, err error) { - fi, err := os.Stat(name) - if err != nil { - return - } - match = (fi.Mode() & modemask) == modemask - return -} - -func (s *Session) pwd() string { - dir := string(s.dir) - if dir == "" { - dir, _ = os.Getwd() - } - return dir -} - -func (s *Session) abspath(name string) string { - if filepath.IsAbs(name) { - return name - } - return filepath.Join(s.pwd(), name) -} - -func init() { - //log.SetFlags(log.Lshortfile | log.LstdFlags) -} - -// expression can be dir, file, link -func (s *Session) Test(expression string, argument string) bool { - var err error - var fi os.FileInfo - fi, err = os.Lstat(s.abspath(argument)) - switch expression { - case "d", "dir": - return err == nil && fi.IsDir() - case "f", "file": - return err == nil && fi.Mode().IsRegular() - case "x", "executable": - /* - fmt.Println(expression, argument) - if err == nil { - fmt.Println(fi.Mode()) - } - */ - return err == nil && fi.Mode()&os.FileMode(0100) != 0 - case "L", "link": - return err == nil && fi.Mode()&os.ModeSymlink != 0 - } - return false -} - -// expression can be d,dir, f,file, link -func Test(exp string, arg string) bool { - s := NewSession() - return s.Test(exp, arg) -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/test_test.go b/plugins/network/vendor/github.com/codeskyblue/go-sh/test_test.go deleted file mode 100644 index 15225aa9a..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/test_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package sh_test - -import ( - "testing" - - "github.com/codeskyblue/go-sh" -) - -var s = sh.NewSession() - -type T struct{ *testing.T } - -func NewT(t *testing.T) *T { - return &T{t} -} - -func (t *T) checkTest(exp string, arg string, result bool) { - r := s.Test(exp, arg) - if r != result { - t.Errorf("test -%s %s, %v != %v", exp, arg, r, result) - } -} - -func TestTest(i *testing.T) { - t := NewT(i) - t.checkTest("d", "../go-sh", true) - t.checkTest("d", "./yymm", false) - - // file test - t.checkTest("f", "testdata/hello.txt", true) - t.checkTest("f", "testdata/xxxxx", false) - t.checkTest("f", "testdata/yymm", false) - - // link test - t.checkTest("link", "testdata/linkfile", true) - t.checkTest("link", "testdata/xxxxxlinkfile", false) - t.checkTest("link", "testdata/hello.txt", false) - - // executable test - t.checkTest("x", "testdata/executable", true) - t.checkTest("x", "testdata/xxxxx", false) - t.checkTest("x", "testdata/hello.txt", false) -} - -func ExampleShellTest(t *testing.T) { - // test -L - sh.Test("link", "testdata/linkfile") - sh.Test("L", "testdata/linkfile") - // test -f - sh.Test("file", "testdata/file") - sh.Test("f", "testdata/file") - // test -x - sh.Test("executable", "testdata/binfile") - sh.Test("x", "testdata/binfile") - // test -d - sh.Test("dir", "testdata/dir") - sh.Test("d", "testdata/dir") -} diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/testdata/executable b/plugins/network/vendor/github.com/codeskyblue/go-sh/testdata/executable deleted file mode 100755 index e69de29bb..000000000 diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/testdata/hello.txt b/plugins/network/vendor/github.com/codeskyblue/go-sh/testdata/hello.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/testdata/linkfile b/plugins/network/vendor/github.com/codeskyblue/go-sh/testdata/linkfile deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/network/vendor/github.com/codeskyblue/go-sh/wercker.yml b/plugins/network/vendor/github.com/codeskyblue/go-sh/wercker.yml deleted file mode 100644 index 72c47020f..000000000 --- a/plugins/network/vendor/github.com/codeskyblue/go-sh/wercker.yml +++ /dev/null @@ -1,28 +0,0 @@ -box: wercker/golang -# Build definition -build: - # The steps that will be executed on build - steps: - # Sets the go workspace and places you package - # at the right place in the workspace tree - - setup-go-workspace - - # Gets the dependencies - - script: - name: go get - code: | - cd $WERCKER_SOURCE_DIR - go version - go get -t . - - # Build the project - - script: - name: go build - code: | - go build . - - # Test the project - - script: - name: go test - code: | - go test -v ./... diff --git a/plugins/network/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/network/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/network/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/network/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/network/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/network/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/network/vendor/github.com/ryanuber/columnize/README.md b/plugins/network/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/network/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/network/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/network/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/network/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/network/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/network/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/network/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/proxy/glide.yaml b/plugins/proxy/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/proxy/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/proxy/go.mod b/plugins/proxy/go.mod new file mode 100644 index 000000000..165889ac8 --- /dev/null +++ b/plugins/proxy/go.mod @@ -0,0 +1,13 @@ +module github.com/dokku/dokku/plugins/proxy + +go 1.14 + +require ( + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 // indirect + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000 + github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 +) + +replace github.com/dokku/dokku/plugins/common => ../common +replace github.com/dokku/dokku/plugins/config => ../config diff --git a/plugins/proxy/go.sum b/plugins/proxy/go.sum new file mode 100644 index 000000000..6d8e1933b --- /dev/null +++ b/plugins/proxy/go.sum @@ -0,0 +1,47 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/proxy/src/commands/commands.go b/plugins/proxy/src/commands/commands.go index e4f76ce0d..894a9013e 100644 --- a/plugins/proxy/src/commands/commands.go +++ b/plugins/proxy/src/commands/commands.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - columnize "github.com/ryanuber/columnize" ) const ( @@ -60,11 +59,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/proxy/src/glide.lock b/plugins/proxy/src/glide.lock deleted file mode 100644 index fe4a98f07..000000000 --- a/plugins/proxy/src/glide.lock +++ /dev/null @@ -1,6 +0,0 @@ -hash: 1ddab5de41d1514c2722bd7e24758ad4b60bf6956eb5b9b925fa071a1427f149 -updated: 2017-01-03T17:16:50.97156327-08:00 -imports: -- name: github.com/ryanuber/columnize - version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360 -testImports: [] diff --git a/plugins/proxy/src/glide.yaml b/plugins/proxy/src/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/proxy/src/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/proxy/src/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/proxy/src/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/proxy/src/vendor/github.com/ryanuber/columnize/README.md b/plugins/proxy/src/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/proxy/src/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/proxy/src/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/proxy/src/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/proxy/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/proxy/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/proxy/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/proxy/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/proxy/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/proxy/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/proxy/vendor/github.com/ryanuber/columnize/README.md b/plugins/proxy/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/proxy/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/proxy/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/proxy/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/proxy/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/proxy/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/proxy/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/proxy/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/repo/go.mod b/plugins/repo/go.mod new file mode 100644 index 000000000..3588d0833 --- /dev/null +++ b/plugins/repo/go.mod @@ -0,0 +1,12 @@ +module github.com/dokku/dokku/plugins/repo + +go 1.14 + +require ( + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 // indirect + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000 +) + +replace github.com/dokku/dokku/plugins/common => ../common +replace github.com/dokku/dokku/plugins/config => ../config diff --git a/plugins/repo/go.sum b/plugins/repo/go.sum new file mode 100644 index 000000000..6d8e1933b --- /dev/null +++ b/plugins/repo/go.sum @@ -0,0 +1,47 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/repo/src/commands/commands.go b/plugins/repo/src/commands/commands.go index e7aae8f06..92a5a80c9 100644 --- a/plugins/repo/src/commands/commands.go +++ b/plugins/repo/src/commands/commands.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - columnize "github.com/ryanuber/columnize" ) const ( @@ -53,11 +52,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/repo/src/glide.lock b/plugins/repo/src/glide.lock deleted file mode 100644 index fe4a98f07..000000000 --- a/plugins/repo/src/glide.lock +++ /dev/null @@ -1,6 +0,0 @@ -hash: 1ddab5de41d1514c2722bd7e24758ad4b60bf6956eb5b9b925fa071a1427f149 -updated: 2017-01-03T17:16:50.97156327-08:00 -imports: -- name: github.com/ryanuber/columnize - version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360 -testImports: [] diff --git a/plugins/repo/src/glide.yaml b/plugins/repo/src/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/repo/src/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/repo/src/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/repo/src/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/repo/src/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/repo/src/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/repo/src/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/repo/src/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/repo/src/vendor/github.com/ryanuber/columnize/README.md b/plugins/repo/src/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/repo/src/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/repo/src/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/repo/src/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/repo/src/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/repo/src/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/repo/src/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/repo/src/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/resource/glide.yaml b/plugins/resource/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/resource/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/resource/go.mod b/plugins/resource/go.mod new file mode 100644 index 000000000..ec4d3930c --- /dev/null +++ b/plugins/resource/go.mod @@ -0,0 +1,11 @@ +module github.com/dokku/dokku/plugins/resource + +go 1.14 + +require ( + github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 // indirect + github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000 + github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 +) + +replace github.com/dokku/dokku/plugins/common => ../common diff --git a/plugins/resource/go.sum b/plugins/resource/go.sum new file mode 100644 index 000000000..6f9bd8d8d --- /dev/null +++ b/plugins/resource/go.sum @@ -0,0 +1,45 @@ +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= +github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA= +github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= +github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/plugins/resource/src/commands/commands.go b/plugins/resource/src/commands/commands.go index 46cbd806b..0c155a7b1 100644 --- a/plugins/resource/src/commands/commands.go +++ b/plugins/resource/src/commands/commands.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/dokku/dokku/plugins/common" - columnize "github.com/ryanuber/columnize" ) const ( @@ -56,11 +55,5 @@ func main() { } func usage() { - config := columnize.DefaultConfig() - config.Delim = "," - config.Prefix = " " - config.Empty = "" - content := strings.Split(helpContent, "\n")[1:] - fmt.Println(helpHeader) - fmt.Println(columnize.Format(content, config)) + common.CommandUsage(helpHeader, helpContent) } diff --git a/plugins/resource/src/glide.lock b/plugins/resource/src/glide.lock deleted file mode 100644 index fe4a98f07..000000000 --- a/plugins/resource/src/glide.lock +++ /dev/null @@ -1,6 +0,0 @@ -hash: 1ddab5de41d1514c2722bd7e24758ad4b60bf6956eb5b9b925fa071a1427f149 -updated: 2017-01-03T17:16:50.97156327-08:00 -imports: -- name: github.com/ryanuber/columnize - version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360 -testImports: [] diff --git a/plugins/resource/src/glide.yaml b/plugins/resource/src/glide.yaml deleted file mode 100644 index 3f7a96657..000000000 --- a/plugins/resource/src/glide.yaml +++ /dev/null @@ -1,3 +0,0 @@ -package: . -import: -- package: github.com/ryanuber/columnize diff --git a/plugins/resource/src/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/resource/src/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/resource/src/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/resource/src/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/resource/src/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/resource/src/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/resource/src/vendor/github.com/ryanuber/columnize/README.md b/plugins/resource/src/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/resource/src/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/resource/src/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/resource/src/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/resource/src/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/resource/src/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/resource/src/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/resource/src/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -} diff --git a/plugins/resource/vendor/github.com/ryanuber/columnize/.travis.yml b/plugins/resource/vendor/github.com/ryanuber/columnize/.travis.yml deleted file mode 100644 index 1a0bbea6c..000000000 --- a/plugins/resource/vendor/github.com/ryanuber/columnize/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: go -go: - - tip diff --git a/plugins/resource/vendor/github.com/ryanuber/columnize/LICENSE b/plugins/resource/vendor/github.com/ryanuber/columnize/LICENSE deleted file mode 100644 index b9c0e2b68..000000000 --- a/plugins/resource/vendor/github.com/ryanuber/columnize/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2016 Ryan Uber - -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/plugins/resource/vendor/github.com/ryanuber/columnize/README.md b/plugins/resource/vendor/github.com/ryanuber/columnize/README.md deleted file mode 100644 index e47634fc6..000000000 --- a/plugins/resource/vendor/github.com/ryanuber/columnize/README.md +++ /dev/null @@ -1,69 +0,0 @@ -Columnize -========= - -Easy column-formatted output for golang - -[![Build Status](https://travis-ci.org/ryanuber/columnize.svg)](https://travis-ci.org/ryanuber/columnize) -[![GoDoc](https://godoc.org/github.com/ryanuber/columnize?status.svg)](https://godoc.org/github.com/ryanuber/columnize) - -Columnize is a really small Go package that makes building CLI's a little bit -easier. In some CLI designs, you want to output a number similar items in a -human-readable way with nicely aligned columns. However, figuring out how wide -to make each column is a boring problem to solve and eats your valuable time. - -Here is an example: - -```go -package main - -import ( - "fmt" - "github.com/ryanuber/columnize" -) - -func main() { - output := []string{ - "Name | Gender | Age", - "Bob | Male | 38", - "Sally | Female | 26", - } - result := columnize.SimpleFormat(output) - fmt.Println(result) -} -``` - -As you can see, you just pass in a list of strings. And the result: - -``` -Name Gender Age -Bob Male 38 -Sally Female 26 -``` - -Columnize is tolerant of missing or empty fields, or even empty lines, so -passing in extra lines for spacing should show up as you would expect. - -Configuration -============= - -Columnize is configured using a `Config`, which can be obtained by calling the -`DefaultConfig()` method. You can then tweak the settings in the resulting -`Config`: - -``` -config := columnize.DefaultConfig() -config.Delim = "|" -config.Glue = " " -config.Prefix = "" -config.Empty = "" -``` - -* `Delim` is the string by which columns of **input** are delimited -* `Glue` is the string by which columns of **output** are delimited -* `Prefix` is a string by which each line of **output** is prefixed -* `Empty` is a string used to replace blank values found in output - -You can then pass the `Config` in using the `Format` method (signature below) to -have text formatted to your liking. - -See the [godoc](https://godoc.org/github.com/ryanuber/columnize) page for usage. diff --git a/plugins/resource/vendor/github.com/ryanuber/columnize/columnize.go b/plugins/resource/vendor/github.com/ryanuber/columnize/columnize.go deleted file mode 100644 index 915716a10..000000000 --- a/plugins/resource/vendor/github.com/ryanuber/columnize/columnize.go +++ /dev/null @@ -1,178 +0,0 @@ -package columnize - -import ( - "bytes" - "fmt" - "strings" -) - -// Config can be used to tune certain parameters which affect the way -// in which Columnize will format output text. -type Config struct { - // The string by which the lines of input will be split. - Delim string - - // The string by which columns of output will be separated. - Glue string - - // The string by which columns of output will be prefixed. - Prefix string - - // A replacement string to replace empty fields - Empty string -} - -// DefaultConfig returns a *Config with default values. -func DefaultConfig() *Config { - return &Config{ - Delim: "|", - Glue: " ", - Prefix: "", - Empty: "", - } -} - -// MergeConfig merges two config objects together and returns the resulting -// configuration. Values from the right take precedence over the left side. -func MergeConfig(a, b *Config) *Config { - var result Config = *a - - // Return quickly if either side was nil - if a == nil || b == nil { - return &result - } - - if b.Delim != "" { - result.Delim = b.Delim - } - if b.Glue != "" { - result.Glue = b.Glue - } - if b.Prefix != "" { - result.Prefix = b.Prefix - } - if b.Empty != "" { - result.Empty = b.Empty - } - - return &result -} - -// stringFormat, given a set of column widths and the number of columns in -// the current line, returns a sprintf-style format string which can be used -// to print output aligned properly with other lines using the same widths set. -func stringFormat(c *Config, widths []int, columns int) string { - // Create the buffer with an estimate of the length - buf := bytes.NewBuffer(make([]byte, 0, (6+len(c.Glue))*columns)) - - // Start with the prefix, if any was given. The buffer will not return an - // error so it does not need to be handled - buf.WriteString(c.Prefix) - - // Create the format string from the discovered widths - for i := 0; i < columns && i < len(widths); i++ { - if i == columns-1 { - buf.WriteString("%s\n") - } else { - fmt.Fprintf(buf, "%%-%ds%s", widths[i], c.Glue) - } - } - return buf.String() -} - -// elementsFromLine returns a list of elements, each representing a single -// item which will belong to a column of output. -func elementsFromLine(config *Config, line string) []interface{} { - seperated := strings.Split(line, config.Delim) - elements := make([]interface{}, len(seperated)) - for i, field := range seperated { - value := strings.TrimSpace(field) - - // Apply the empty value, if configured. - if value == "" && config.Empty != "" { - value = config.Empty - } - elements[i] = value - } - return elements -} - -// runeLen calculates the number of visible "characters" in a string -func runeLen(s string) int { - l := 0 - for _ = range s { - l++ - } - return l -} - -// widthsFromLines examines a list of strings and determines how wide each -// column should be considering all of the elements that need to be printed -// within it. -func widthsFromLines(config *Config, lines []string) []int { - widths := make([]int, 0, 8) - - for _, line := range lines { - elems := elementsFromLine(config, line) - for i := 0; i < len(elems); i++ { - l := runeLen(elems[i].(string)) - if len(widths) <= i { - widths = append(widths, l) - } else if widths[i] < l { - widths[i] = l - } - } - } - return widths -} - -// Format is the public-facing interface that takes a list of strings and -// returns nicely aligned column-formatted text. -func Format(lines []string, config *Config) string { - conf := MergeConfig(DefaultConfig(), config) - widths := widthsFromLines(conf, lines) - - // Estimate the buffer size - glueSize := len(conf.Glue) - var size int - for _, w := range widths { - size += w + glueSize - } - size *= len(lines) - - // Create the buffer - buf := bytes.NewBuffer(make([]byte, 0, size)) - - // Create a cache for the string formats - fmtCache := make(map[int]string, 16) - - // Create the formatted output using the format string - for _, line := range lines { - elems := elementsFromLine(conf, line) - - // Get the string format using cache - numElems := len(elems) - stringfmt, ok := fmtCache[numElems] - if !ok { - stringfmt = stringFormat(conf, widths, numElems) - fmtCache[numElems] = stringfmt - } - - fmt.Fprintf(buf, stringfmt, elems...) - } - - // Get the string result - result := buf.String() - - // Remove trailing newline without removing leading/trailing space - if n := len(result); n > 0 && result[n-1] == '\n' { - result = result[:n-1] - } - - return result -} - -// SimpleFormat is a convenience function to format text with the defaults. -func SimpleFormat(lines []string) string { - return Format(lines, nil) -} diff --git a/plugins/resource/vendor/github.com/ryanuber/columnize/columnize_test.go b/plugins/resource/vendor/github.com/ryanuber/columnize/columnize_test.go deleted file mode 100644 index 89dabaa38..000000000 --- a/plugins/resource/vendor/github.com/ryanuber/columnize/columnize_test.go +++ /dev/null @@ -1,306 +0,0 @@ -package columnize - -import ( - "fmt" - "testing" - - crand "crypto/rand" -) - -func TestListOfStringsInput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyLinesOutput(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestLeadingSpacePreserved(t *testing.T) { - input := []string{ - "| Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := " Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestColumnWidthCalculator(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Longer than A | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Longer than A Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func TestColumnWidthCalculatorNonASCII(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "⌘⌘⌘⌘⌘⌘⌘⌘ | Longer than B | Longer than C", - "short | short | short", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "⌘⌘⌘⌘⌘⌘⌘⌘ Longer than B Longer than C\n" - expected += "short short short" - - if output != expected { - printableProof := fmt.Sprintf("\nGot: %+q", output) - printableProof += fmt.Sprintf("\nExpected: %+q", expected) - t.Fatalf("\n%s", printableProof) - } -} - -func BenchmarkColumnWidthCalculator(b *testing.B) { - // Generate the input - input := []string{ - "UUID A | UUID B | UUID C | Column D | Column E", - } - - format := "%s|%s|%s|%s" - short := "short" - - uuid := func() string { - buf := make([]byte, 16) - if _, err := crand.Read(buf); err != nil { - panic(fmt.Errorf("failed to read random bytes: %v", err)) - } - - return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x", - buf[0:4], - buf[4:6], - buf[6:8], - buf[8:10], - buf[10:16]) - } - - for i := 0; i < 1000; i++ { - l := fmt.Sprintf(format, uuid()[:8], uuid()[:12], uuid(), short, short) - input = append(input, l) - } - - config := DefaultConfig() - b.ResetTimer() - - for i := 0; i < b.N; i++ { - Format(input, config) - } -} - -func TestVariedInputSpacing(t *testing.T) { - input := []string{ - "Column A |Column B| Column C", - "x|y| z", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestUnmatchedColumnCounts(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "Value A | Value B", - "Value A | Value B | Value C | Value D", - } - - config := DefaultConfig() - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "Value A Value B\n" - expected += "Value A Value B Value C Value D" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateDelimiter(t *testing.T) { - input := []string{ - "Column | A % Column | B % Column | C", - "Value A % Value B % Value C", - } - - config := DefaultConfig() - config.Delim = "%" - output := Format(input, config) - - expected := "Column | A Column | B Column | C\n" - expected += "Value A Value B Value C" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternateSpacingString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Glue = " " - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestSimpleFormat(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - output := SimpleFormat(input) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestAlternatePrefixString(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := DefaultConfig() - config.Prefix = " " - output := Format(input, config) - - expected := " Column A Column B Column C\n" - expected += " x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyFieldReplacement(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | | z", - } - - config := DefaultConfig() - config.Empty = "" - output := Format(input, config) - - expected := "Column A Column B Column C\n" - expected += "x z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestEmptyConfigValues(t *testing.T) { - input := []string{ - "Column A | Column B | Column C", - "x | y | z", - } - - config := Config{} - output := Format(input, &config) - - expected := "Column A Column B Column C\n" - expected += "x y z" - - if output != expected { - t.Fatalf("\nexpected:\n%s\n\ngot:\n%s", expected, output) - } -} - -func TestMergeConfig(t *testing.T) { - conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"} - conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"} - conf3 := &Config{Delim: "c", Prefix: "c"} - - m := MergeConfig(conf1, conf2) - if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, conf3) - if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, nil) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } - - m = MergeConfig(conf1, &Config{}) - if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" { - t.Fatalf("bad: %#v", m) - } -}