[config] update glide dependencies
This commit is contained in:
1 parent
8e8b6d60f0
commit
a13722eec1
9 files changed
+128
-56
No files matched your search
Generated
+5
-4
@@ -1,7 +1,8 @@
|
|||||||
hash: 998d313aef819c8fa68d268d075079d281a7ccab0c3a16f6d8906b20c902f627
|
hash: 84462ba8482aa8c12a928ab1851f212d558df5036311ec22469fdf86b77cbcad
|
||||||
updated: 2017-05-20T15:15:41.795778946-04:00
|
updated: 2017-07-25T23:17:54.615885635-04:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/alexquick/godotenv
|
- name: github.com/alexquick/godotenv
|
||||||
version: 147552bee9c6196b9388f15ab03fe15721264092
|
version: 84c21eea73c643434a7b128dab043ffea44b80d9
|
||||||
- name: github.com/ryanuber/columnize
|
- name: github.com/ryanuber/columnize
|
||||||
version: 0fbbb3f0e3fbdc5bae7c6cd5f6c1887ebfb76360
|
version: abc90934186a77966e2beeac62ed966aac0561d5
|
||||||
|
testImports: []
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package: .
|
package: github.com/dokku/dokku/plugins/config
|
||||||
|
ignore:
|
||||||
|
- github.com/dokku/dokku/plugins/common
|
||||||
|
- github.com/onsi/gomega
|
||||||
import:
|
import:
|
||||||
- package: github.com/ryanuber/columnize
|
- package: github.com/ryanuber/columnize
|
||||||
- package: github.com/alexquick/godotenv
|
- package: github.com/alexquick/godotenv
|
||||||
version: master
|
version: ^1.1.0
|
||||||
@@ -138,7 +138,7 @@ func LoadGlobal() (*Env, error) {
|
|||||||
|
|
||||||
//NewFromString creates an env from the given ENVFILE contents representation
|
//NewFromString creates an env from the given ENVFILE contents representation
|
||||||
func NewFromString(rep string) (*Env, error) {
|
func NewFromString(rep string) (*Env, error) {
|
||||||
envMap, err := godotenv.ReadFromReader(strings.NewReader(rep))
|
envMap, err := godotenv.ReadString(rep)
|
||||||
env := &Env{
|
env := &Env{
|
||||||
"<unknown>",
|
"<unknown>",
|
||||||
"",
|
"",
|
||||||
|
|||||||
+7
-1
@@ -118,9 +118,15 @@ Contributions are most welcome! The parser itself is pretty stupidly naive and I
|
|||||||
4. Push to the branch (`git push origin my-new-feature`)
|
4. Push to the branch (`git push origin my-new-feature`)
|
||||||
5. Create new Pull Request
|
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
|
## CI
|
||||||
|
|
||||||
Linux: [](https://app.wercker.com/project/bykey/507594c2ec7e60f19403a568dfea0f78) Windows: [](https://ci.appveyor.com/project/joho/godotenv)
|
Linux: [](https://travis-ci.org/joho/godotenv) Windows: [](https://ci.appveyor.com/project/joho/godotenv)
|
||||||
|
|
||||||
## Who?
|
## Who?
|
||||||
|
|
||||||
|
|||||||
+22
-13
@@ -25,6 +25,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const doubleQuoteSpecialChars = "\\\n\r\"!$`"
|
||||||
|
|
||||||
// Load will read your env file(s) and load them into ENV for this process.
|
// 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)
|
// Call this function as close as possible to the start of your program (ideally in main)
|
||||||
@@ -93,6 +95,11 @@ func Read(filenames ...string) (envMap map[string]string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadString parses an environment file from dotenv file contents returning it as a map
|
||||||
|
func ReadString(content string) (envMap map[string]string, err error) {
|
||||||
|
return read(strings.NewReader(content))
|
||||||
|
}
|
||||||
|
|
||||||
// Exec loads env vars from the specified filenames (empty map falls back to default)
|
// Exec loads env vars from the specified filenames (empty map falls back to default)
|
||||||
// then executes the cmd specified.
|
// then executes the cmd specified.
|
||||||
//
|
//
|
||||||
@@ -171,14 +178,10 @@ func readFile(filename string) (envMap map[string]string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
return ReadFromReader(file)
|
return read(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readString(content string) (envMap map[string]string, err error) {
|
func read(r io.Reader) (envMap map[string]string, err error) {
|
||||||
return ReadFromReader(strings.NewReader(content))
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadFromReader(r io.Reader) (envMap map[string]string, err error) {
|
|
||||||
envMap = make(map[string]string)
|
envMap = make(map[string]string)
|
||||||
|
|
||||||
var lines []string
|
var lines []string
|
||||||
@@ -243,7 +246,7 @@ func parseLine(line string) (key string, value string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(splitString) != 2 {
|
if len(splitString) != 2 {
|
||||||
err = errors.New("Can't separate key from value for line: " + line)
|
err = errors.New("Can't separate key from value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,8 +267,8 @@ func parseValue(value string) string {
|
|||||||
// trim
|
// trim
|
||||||
value = strings.Trim(value, " ")
|
value = strings.Trim(value, " ")
|
||||||
|
|
||||||
// check if we've got quoted values
|
// check if we've got quoted values or possible escapes
|
||||||
if value != "" {
|
if len(value) > 1 {
|
||||||
first := string(value[0:1])
|
first := string(value[0:1])
|
||||||
last := string(value[len(value)-1:])
|
last := string(value[len(value)-1:])
|
||||||
if first == last && strings.ContainsAny(first, `"'`) {
|
if first == last && strings.ContainsAny(first, `"'`) {
|
||||||
@@ -296,9 +299,15 @@ func isIgnoredLine(line string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doubleQuoteEscape(line string) string {
|
func doubleQuoteEscape(line string) string {
|
||||||
line = strings.Replace(line, `\`, `\\`, -1)
|
for _, c := range doubleQuoteSpecialChars {
|
||||||
line = strings.Replace(line, "\n", `\n`, -1)
|
toReplace := "\\" + string(c)
|
||||||
line = strings.Replace(line, "\r", `\r`, -1)
|
if c == '\n' {
|
||||||
line = strings.Replace(line, `"`, `\"`, -1)
|
toReplace = `\n`
|
||||||
|
}
|
||||||
|
if c == '\r' {
|
||||||
|
toReplace = `\r`
|
||||||
|
}
|
||||||
|
line = strings.Replace(line, string(c), toReplace, -1)
|
||||||
|
}
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
+8
-4
@@ -254,6 +254,10 @@ func TestParsing(t *testing.T) {
|
|||||||
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, `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
|
// it 'throws an error if line format is incorrect' do
|
||||||
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
||||||
badlyFormattedLine := "lol$wut"
|
badlyFormattedLine := "lol$wut"
|
||||||
@@ -309,7 +313,7 @@ func TestErrorParsing(t *testing.T) {
|
|||||||
|
|
||||||
func TestWrite(t *testing.T) {
|
func TestWrite(t *testing.T) {
|
||||||
writeAndCompare := func(env string, expected string) {
|
writeAndCompare := func(env string, expected string) {
|
||||||
envMap, _ := readString(env)
|
envMap, _ := ReadString(env)
|
||||||
actual, _ := WriteString(envMap)
|
actual, _ := WriteString(envMap)
|
||||||
if expected != actual {
|
if expected != actual {
|
||||||
t.Errorf("Expected '%v' (%v) to write as '%v', got '%v' instead.", env, envMap, expected, actual)
|
t.Errorf("Expected '%v' (%v) to write as '%v', got '%v' instead.", env, envMap, expected, actual)
|
||||||
@@ -324,8 +328,8 @@ func TestWrite(t *testing.T) {
|
|||||||
writeAndCompare(`key=va"lu"e`, `key="va\"lu\"e"`)
|
writeAndCompare(`key=va"lu"e`, `key="va\"lu\"e"`)
|
||||||
//but single quotes are left alone
|
//but single quotes are left alone
|
||||||
writeAndCompare(`key=va'lu'e`, `key="va'lu'e"`)
|
writeAndCompare(`key=va'lu'e`, `key="va'lu'e"`)
|
||||||
// newlines and backslashes are escaped
|
// newlines, backslashes, and some other special chars are escaped
|
||||||
writeAndCompare(`foo="ba\n\r\\r!"`, `foo="ba\n\r\\r!"`)
|
writeAndCompare(`foo="$ba\n\r\\r!"`, `foo="\$ba\n\r\\r\!"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRoundtrip(t *testing.T) {
|
func TestRoundtrip(t *testing.T) {
|
||||||
@@ -340,7 +344,7 @@ func TestRoundtrip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
roundtripped, err := readString(rep)
|
roundtripped, err := ReadString(rep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -56,12 +56,14 @@ config.Delim = "|"
|
|||||||
config.Glue = " "
|
config.Glue = " "
|
||||||
config.Prefix = ""
|
config.Prefix = ""
|
||||||
config.Empty = ""
|
config.Empty = ""
|
||||||
|
config.NoTrim = false
|
||||||
```
|
```
|
||||||
|
|
||||||
* `Delim` is the string by which columns of **input** are delimited
|
* `Delim` is the string by which columns of **input** are delimited
|
||||||
* `Glue` is the string by which columns of **output** 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
|
* `Prefix` is a string by which each line of **output** is prefixed
|
||||||
* `Empty` is a string used to replace blank values found in output
|
* `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
|
You can then pass the `Config` in using the `Format` method (signature below) to
|
||||||
have text formatted to your liking.
|
have text formatted to your liking.
|
||||||
|
|||||||
+22
-9
@@ -18,8 +18,11 @@ type Config struct {
|
|||||||
// The string by which columns of output will be prefixed.
|
// The string by which columns of output will be prefixed.
|
||||||
Prefix string
|
Prefix string
|
||||||
|
|
||||||
// A replacement string to replace empty fields
|
// A replacement string to replace empty fields.
|
||||||
Empty string
|
Empty string
|
||||||
|
|
||||||
|
// NoTrim disables automatic trimming of inputs.
|
||||||
|
NoTrim bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConfig returns a *Config with default values.
|
// DefaultConfig returns a *Config with default values.
|
||||||
@@ -29,18 +32,22 @@ func DefaultConfig() *Config {
|
|||||||
Glue: " ",
|
Glue: " ",
|
||||||
Prefix: "",
|
Prefix: "",
|
||||||
Empty: "",
|
Empty: "",
|
||||||
|
NoTrim: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergeConfig merges two config objects together and returns the resulting
|
// MergeConfig merges two config objects together and returns the resulting
|
||||||
// configuration. Values from the right take precedence over the left side.
|
// configuration. Values from the right take precedence over the left side.
|
||||||
func MergeConfig(a, b *Config) *Config {
|
func MergeConfig(a, b *Config) *Config {
|
||||||
var result Config = *a
|
|
||||||
|
|
||||||
// Return quickly if either side was nil
|
// Return quickly if either side was nil
|
||||||
if a == nil || b == nil {
|
if a == nil {
|
||||||
return &result
|
return b
|
||||||
}
|
}
|
||||||
|
if b == nil {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
var result Config = *a
|
||||||
|
|
||||||
if b.Delim != "" {
|
if b.Delim != "" {
|
||||||
result.Delim = b.Delim
|
result.Delim = b.Delim
|
||||||
@@ -54,6 +61,9 @@ func MergeConfig(a, b *Config) *Config {
|
|||||||
if b.Empty != "" {
|
if b.Empty != "" {
|
||||||
result.Empty = b.Empty
|
result.Empty = b.Empty
|
||||||
}
|
}
|
||||||
|
if b.NoTrim {
|
||||||
|
result.NoTrim = true
|
||||||
|
}
|
||||||
|
|
||||||
return &result
|
return &result
|
||||||
}
|
}
|
||||||
@@ -83,10 +93,13 @@ func stringFormat(c *Config, widths []int, columns int) string {
|
|||||||
// elementsFromLine returns a list of elements, each representing a single
|
// elementsFromLine returns a list of elements, each representing a single
|
||||||
// item which will belong to a column of output.
|
// item which will belong to a column of output.
|
||||||
func elementsFromLine(config *Config, line string) []interface{} {
|
func elementsFromLine(config *Config, line string) []interface{} {
|
||||||
seperated := strings.Split(line, config.Delim)
|
separated := strings.Split(line, config.Delim)
|
||||||
elements := make([]interface{}, len(seperated))
|
elements := make([]interface{}, len(separated))
|
||||||
for i, field := range seperated {
|
for i, field := range separated {
|
||||||
value := strings.TrimSpace(field)
|
value := field
|
||||||
|
if !config.NoTrim {
|
||||||
|
value = strings.TrimSpace(field)
|
||||||
|
}
|
||||||
|
|
||||||
// Apply the empty value, if configured.
|
// Apply the empty value, if configured.
|
||||||
if value == "" && config.Empty != "" {
|
if value == "" && config.Empty != "" {
|
||||||
|
|||||||
+56
-22
@@ -2,6 +2,7 @@ package columnize
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
@@ -155,6 +156,24 @@ func TestVariedInputSpacing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
func TestUnmatchedColumnCounts(t *testing.T) {
|
||||||
input := []string{
|
input := []string{
|
||||||
"Column A | Column B | Column C",
|
"Column A | Column B | Column C",
|
||||||
@@ -280,27 +299,42 @@ func TestEmptyConfigValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeConfig(t *testing.T) {
|
func TestMergeConfig(t *testing.T) {
|
||||||
conf1 := &Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"}
|
for _, tc := range []struct {
|
||||||
conf2 := &Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"}
|
desc string
|
||||||
conf3 := &Config{Delim: "c", Prefix: "c"}
|
configA *Config
|
||||||
|
configB *Config
|
||||||
m := MergeConfig(conf1, conf2)
|
expect *Config
|
||||||
if m.Delim != "b" || m.Glue != "b" || m.Prefix != "b" || m.Empty != "b" {
|
}{
|
||||||
t.Fatalf("bad: %#v", m)
|
{
|
||||||
}
|
"merges b over a",
|
||||||
|
&Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"},
|
||||||
m = MergeConfig(conf1, conf3)
|
&Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"},
|
||||||
if m.Delim != "c" || m.Glue != "a" || m.Prefix != "c" || m.Empty != "a" {
|
&Config{Delim: "b", Glue: "b", Prefix: "b", Empty: "b"},
|
||||||
t.Fatalf("bad: %#v", m)
|
},
|
||||||
}
|
{
|
||||||
|
"merges only non-empty config values",
|
||||||
m = MergeConfig(conf1, nil)
|
&Config{Delim: "a", Glue: "a", Prefix: "a", Empty: "a"},
|
||||||
if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" {
|
&Config{Delim: "b", Prefix: "b"},
|
||||||
t.Fatalf("bad: %#v", m)
|
&Config{Delim: "b", Glue: "a", Prefix: "b", Empty: "a"},
|
||||||
}
|
},
|
||||||
|
{
|
||||||
m = MergeConfig(conf1, &Config{})
|
"takes b if a is nil",
|
||||||
if m.Delim != "a" || m.Glue != "a" || m.Prefix != "a" || m.Empty != "a" {
|
nil,
|
||||||
t.Fatalf("bad: %#v", m)
|
&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)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user