From 2e59b07d58b76dd7e8c1a26d5815b8eb0d3717a3 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 14 Jun 2021 19:16:57 -0700 Subject: [PATCH 01/17] jpp: fork jpp command from jp version 0.1.3 Rename the command from jp to jpp and nothing more. --- cmd/jpp/main.go | 122 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 cmd/jpp/main.go diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go new file mode 100644 index 0000000..e2d96ad --- /dev/null +++ b/cmd/jpp/main.go @@ -0,0 +1,122 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + + "github.com/jmespath/jp/Godeps/_workspace/src/github.com/codegangsta/cli" + "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" +) + +const version = "0.1.3" + +func main() { + app := cli.NewApp() + app.Name = "jpp" + app.Version = version + app.Usage = "jpp [] " + app.Author = "" + app.Email = "" + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "filename, f", + Usage: "Read input JSON from a file instead of stdin.", + }, + cli.StringFlag{ + Name: "expr-file, e", + Usage: "Read JMESPath expression from the specified file.", + }, + cli.BoolFlag{ + Name: "unquoted, u", + Usage: "If the final result is a string, it will be printed without quotes.", + }, + cli.BoolFlag{ + Name: "ast", + Usage: "Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes.", + }, + } + app.Action = runMainAndExit + + app.Run(os.Args) +} + +func runMainAndExit(c *cli.Context) { + os.Exit(runMain(c)) +} + +func errMsg(msg string, a ...interface{}) int { + fmt.Fprintf(os.Stderr, msg, a...) + fmt.Fprintln(os.Stderr) + return 1 +} + +func runMain(c *cli.Context) int { + var expression string + if c.String("expr-file") != "" { + byteExpr, err := ioutil.ReadFile(c.String("expr-file")) + expression = string(byteExpr) + if err != nil { + return errMsg("Error opening expression file: %s", err) + } + } else { + if len(c.Args()) == 0 { + return errMsg("Must provide at least one argument.") + } + expression = c.Args()[0] + } + if c.Bool("ast") { + parser := jmespath.NewParser() + parsed, err := parser.Parse(expression) + if err != nil { + if syntaxError, ok := err.(jmespath.SyntaxError); ok { + return errMsg("%s\n%s\n", + syntaxError, + syntaxError.HighlightLocation()) + } + return errMsg("%s", err) + } + fmt.Println("") + fmt.Printf("%s\n", parsed) + return 0 + } + var input interface{} + var jsonParser *json.Decoder + if c.String("filename") != "" { + f, err := os.Open(c.String("filename")) + if err != nil { + return errMsg("Error opening input file: %s", err) + } + jsonParser = json.NewDecoder(f) + + } else { + jsonParser = json.NewDecoder(os.Stdin) + } + if err := jsonParser.Decode(&input); err != nil { + errMsg("Error parsing input json: %s\n", err) + return 2 + } + result, err := jmespath.Search(expression, input) + if err != nil { + if syntaxError, ok := err.(jmespath.SyntaxError); ok { + return errMsg("%s\n%s\n", + syntaxError, + syntaxError.HighlightLocation()) + } + return errMsg("Error evaluating JMESPath expression: %s", err) + } + converted, isString := result.(string) + if c.Bool("unquoted") && isString { + os.Stdout.WriteString(converted) + } else { + toJSON, err := json.MarshalIndent(result, "", " ") + if err != nil { + errMsg("Error marshalling result to JSON: %s\n", err) + return 3 + } + os.Stdout.Write(toJSON) + } + os.Stdout.WriteString("\n") + return 0 +} From ee7042022fccd01a7494b2fff239894428d24770 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 14 Jun 2021 19:26:58 -0700 Subject: [PATCH 02/17] jpp: Add --compact, -c bool flag to omit nonessential whitespace --- cmd/jpp/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index e2d96ad..fc8f851 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -20,6 +20,10 @@ func main() { app.Author = "" app.Email = "" app.Flags = []cli.Flag{ + cli.BoolFlag{ + Name: "compact, c", + Usage: "Produce compact JSON output that omits nonessential whitespace.", + }, cli.StringFlag{ Name: "filename, f", Usage: "Read input JSON from a file instead of stdin.", @@ -110,7 +114,12 @@ func runMain(c *cli.Context) int { if c.Bool("unquoted") && isString { os.Stdout.WriteString(converted) } else { - toJSON, err := json.MarshalIndent(result, "", " ") + var toJSON []byte + if c.Bool("compact") { + toJSON, err = json.Marshal(result) + } else { + toJSON, err = json.MarshalIndent(result, "", " ") + } if err != nil { errMsg("Error marshalling result to JSON: %s\n", err) return 3 From ba4e8833f8bf3f6c85810319a3753008e72d5620 Mon Sep 17 00:00:00 2001 From: James Haggerty Date: Wed, 9 Aug 2017 10:42:12 +0000 Subject: [PATCH 03/17] jpp: Add --stream, -s bool flag Rebased https://github.com/jmespath/jp/pull/14 on jpp master. --- cmd/jpp/main.go | 64 +++++++++++++++++++++++++----------------- test/cases/search.bats | 11 ++++++++ 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index fc8f851..c68d945 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "io" "io/ioutil" "os" @@ -36,6 +37,10 @@ func main() { Name: "unquoted, u", Usage: "If the final result is a string, it will be printed without quotes.", }, + cli.BoolFlag{ + Name: "stream, s", + Usage: "Parse JSON elements until the input stream is exhausted (rather than just the first).", + }, cli.BoolFlag{ Name: "ast", Usage: "Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes.", @@ -85,7 +90,6 @@ func runMain(c *cli.Context) int { fmt.Printf("%s\n", parsed) return 0 } - var input interface{} var jsonParser *json.Decoder if c.String("filename") != "" { f, err := os.Open(c.String("filename")) @@ -97,35 +101,43 @@ func runMain(c *cli.Context) int { } else { jsonParser = json.NewDecoder(os.Stdin) } - if err := jsonParser.Decode(&input); err != nil { - errMsg("Error parsing input json: %s\n", err) - return 2 - } - result, err := jmespath.Search(expression, input) - if err != nil { - if syntaxError, ok := err.(jmespath.SyntaxError); ok { - return errMsg("%s\n%s\n", - syntaxError, - syntaxError.HighlightLocation()) + for { + var input interface{} + if err := jsonParser.Decode(&input); err == io.EOF { + break + } else if err != nil { + errMsg("Error parsing input json: %s\n", err) + return 2 } - return errMsg("Error evaluating JMESPath expression: %s", err) - } - converted, isString := result.(string) - if c.Bool("unquoted") && isString { - os.Stdout.WriteString(converted) - } else { - var toJSON []byte - if c.Bool("compact") { - toJSON, err = json.Marshal(result) + result, err := jmespath.Search(expression, input) + if err != nil { + if syntaxError, ok := err.(jmespath.SyntaxError); ok { + return errMsg("%s\n%s\n", + syntaxError, + syntaxError.HighlightLocation()) + } + return errMsg("Error evaluating JMESPath expression: %s", err) + } + converted, isString := result.(string) + if c.Bool("unquoted") && isString { + os.Stdout.WriteString(converted) } else { - toJSON, err = json.MarshalIndent(result, "", " ") + var toJSON []byte + if c.Bool("compact") { + toJSON, err = json.Marshal(result) + } else { + toJSON, err = json.MarshalIndent(result, "", " ") + } + if err != nil { + errMsg("Error marshalling result to JSON: %s\n", err) + return 3 + } + os.Stdout.Write(toJSON) } - if err != nil { - errMsg("Error marshalling result to JSON: %s\n", err) - return 3 + os.Stdout.WriteString("\n") + if !c.Bool("stream") { + break } - os.Stdout.Write(toJSON) } - os.Stdout.WriteString("\n") return 0 } diff --git a/test/cases/search.bats b/test/cases/search.bats index 5285185..5a2527d 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -14,6 +14,17 @@ [ "$output" == "\"bar\"" ] } +@test "Ignores subsequent data" { + output=$(echo '{"foo": "bar"}blah' | ./jp foo) + [ "$output" == "\"bar\"" ] +} + +@test "Processes subsequent data in stream mode" { + output=$(echo '{"foo": "bar"}{"foo": "x"}' | ./jpp -s foo) + echo "$output" + [ "$output" == $'\"bar\"\n\"x\"' ] +} + @test "Can search subexpr expression" { output=$(echo '{"foo": {"bar": "baz"}}' | ./jp foo.bar) [ "$output" == "\"baz\"" ] From d75cf886203343d6614a8a722e035cf1fe3d1144 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 14 Jun 2021 20:04:06 -0700 Subject: [PATCH 04/17] jpp: Make stream behavior unconditional and remove --stream, -s flag Mirrors sentiments expressed here: https://github.com/jmespath/jp/pull/14#issuecomment-366522853 https://github.com/jmespath/jp/pull/14#issuecomment-396710077 --- cmd/jpp/main.go | 7 ------- test/cases/search.bats | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index c68d945..33550f8 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -37,10 +37,6 @@ func main() { Name: "unquoted, u", Usage: "If the final result is a string, it will be printed without quotes.", }, - cli.BoolFlag{ - Name: "stream, s", - Usage: "Parse JSON elements until the input stream is exhausted (rather than just the first).", - }, cli.BoolFlag{ Name: "ast", Usage: "Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes.", @@ -135,9 +131,6 @@ func runMain(c *cli.Context) int { os.Stdout.Write(toJSON) } os.Stdout.WriteString("\n") - if !c.Bool("stream") { - break - } } return 0 } diff --git a/test/cases/search.bats b/test/cases/search.bats index 5a2527d..132240a 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -20,7 +20,7 @@ } @test "Processes subsequent data in stream mode" { - output=$(echo '{"foo": "bar"}{"foo": "x"}' | ./jpp -s foo) + output=$(echo '{"foo": "bar"}{"foo": "x"}' | ./jpp foo) echo "$output" [ "$output" == $'\"bar\"\n\"x\"' ] } From 8a08979e22529be138623cec18b65184ba932331 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 14 Jun 2021 20:39:21 -0700 Subject: [PATCH 05/17] jpp: Add --slurp, -s bool flag like jq has Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array. --- cmd/jpp/main.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 33550f8..9b49df4 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -33,6 +33,10 @@ func main() { Name: "expr-file, e", Usage: "Read JMESPath expression from the specified file.", }, + cli.BoolFlag{ + Name: "slurp, s", + Usage: "Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.", + }, cli.BoolFlag{ Name: "unquoted, u", Usage: "If the final result is a string, it will be printed without quotes.", @@ -97,9 +101,26 @@ func runMain(c *cli.Context) int { } else { jsonParser = json.NewDecoder(os.Stdin) } + + var slurpInput []interface{} + if c.Bool("slurp") { + for { + var element interface{} + if err := jsonParser.Decode(&element); err == io.EOF { + break + } else if err != nil { + errMsg("Error parsing input json: %s\n", err) + return 2 + } + slurpInput = append(slurpInput, element) + } + } + for { var input interface{} - if err := jsonParser.Decode(&input); err == io.EOF { + if c.Bool("slurp") { + input = slurpInput + } else if err := jsonParser.Decode(&input); err == io.EOF { break } else if err != nil { errMsg("Error parsing input json: %s\n", err) @@ -131,6 +152,9 @@ func runMain(c *cli.Context) int { os.Stdout.Write(toJSON) } os.Stdout.WriteString("\n") + if c.Bool("slurp") { + break + } } return 0 } From e7989df1056486dbf3e1c3b53a2f208a2023efc9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 14 Jun 2021 21:18:21 -0700 Subject: [PATCH 06/17] jpp: Add --accumulate, -a option which accumulates all output objects into a single recursively merged object This option will accumulate all output objects into a single recursively merged output object. Most of this code comes from the golang playground link posted by Roger Peppe in this "Recursively merge JSON structures" thread: https://groups.google.com/g/golang-nuts/c/nLCy75zMlS8/m/O9ZMubnKCQAJ https://play.golang.org/p/8jlJUbEJKf --- cmd/jpp/main.go | 140 ++++++++++++++++++++++++++++++++++++----- test/cases/search.bats | 12 ++++ 2 files changed, 135 insertions(+), 17 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 9b49df4..5d8d280 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -21,6 +21,10 @@ func main() { app.Author = "" app.Email = "" app.Flags = []cli.Flag{ + cli.BoolFlag{ + Name: "accumulate, a", + Usage: "Accumulate all output objects into a single recursively merged output object.", + }, cli.BoolFlag{ Name: "compact, c", Usage: "Produce compact JSON output that omits nonessential whitespace.", @@ -116,30 +120,59 @@ func runMain(c *cli.Context) int { } } + var accumulator interface{} + eof := false + for { - var input interface{} - if c.Bool("slurp") { - input = slurpInput - } else if err := jsonParser.Decode(&input); err == io.EOF { - break - } else if err != nil { - errMsg("Error parsing input json: %s\n", err) - return 2 - } - result, err := jmespath.Search(expression, input) - if err != nil { - if syntaxError, ok := err.(jmespath.SyntaxError); ok { - return errMsg("%s\n%s\n", - syntaxError, - syntaxError.HighlightLocation()) + var result interface{} + for { + var input interface{} + var err error + if c.Bool("slurp") { + input = slurpInput + } else if err = jsonParser.Decode(&input); err == io.EOF { + eof = true + break + } else if err != nil { + errMsg("Error parsing input json: %s\n", err) + return 2 + } + result, err = jmespath.Search(expression, input) + if err != nil { + if syntaxError, ok := err.(jmespath.SyntaxError); ok { + return errMsg("%s\n%s\n", + syntaxError, + syntaxError.HighlightLocation()) + } + return errMsg("Error evaluating JMESPath expression: %s", err) } - return errMsg("Error evaluating JMESPath expression: %s", err) + + if c.Bool("accumulate") { + if accumulator == nil { + accumulator = result + } else { + accumulator, err = merge(result, accumulator); if err != nil { + errMsg("Error merging output json: %s\n", err) + return 2 + } + } + } else { + break + } + } + + if c.Bool("accumulate") { + result = accumulator + } else if eof { + break } + converted, isString := result.(string) if c.Bool("unquoted") && isString { os.Stdout.WriteString(converted) } else { var toJSON []byte + var err error if c.Bool("compact") { toJSON, err = json.Marshal(result) } else { @@ -152,9 +185,82 @@ func runMain(c *cli.Context) int { os.Stdout.Write(toJSON) } os.Stdout.WriteString("\n") - if c.Bool("slurp") { + if eof || c.Bool("accumulate") || c.Bool("slurp") { break } } return 0 } + +// The following merge and merge1 functions come from the +// golang playground link posted by Roger Peppe in this +// "Recursively merge JSON structures" thread: +// +// https://groups.google.com/g/golang-nuts/c/nLCy75zMlS8/m/O9ZMubnKCQAJ +// https://play.golang.org/p/8jlJUbEJKf + +// merge merges the two JSON-marshalable values x1 and x2, +// preferring x1 over x2 except where x1 and x2 are +// JSON objects, in which case the keys from both objects +// are included and their values merged recursively. +// +// It returns an error if x1 or x2 cannot be JSON-marshaled. +func merge(x1, x2 interface{}) (interface{}, error) { + data1, err := json.Marshal(x1) + if err != nil { + return nil, err + } + data2, err := json.Marshal(x2) + if err != nil { + return nil, err + } + var j1 interface{} + err = json.Unmarshal(data1, &j1) + if err != nil { + return nil, err + } + var j2 interface{} + err = json.Unmarshal(data2, &j2) + if err != nil { + return nil, err + } + return merge1(j1, j2), nil +} + +func merge1(x1, x2 interface{}) interface{} { + switch x1 := x1.(type) { + case map[string]interface{}: + x2, ok := x2.(map[string]interface{}) + if !ok { + return x1 + } + for k, v2 := range x2 { + if v1, ok := x1[k]; ok { + x1[k] = merge1(v1, v2) + } else { + x1[k] = v2 + } + } + case []interface{}: + x2, ok := x2.([]interface{}) + if !ok { + return x1 + } + var result []interface{} + for _, element := range x2 { + result = append(result, element) + } + for _, element := range x1 { + result = append(result, element) + } + return result + case nil: + // merge(nil, map[string]interface{...}) -> map[string]interface{...} + x2, ok := x2.(map[string]interface{}) + if ok { + return x2 + } + } + return x1 +} + diff --git a/test/cases/search.bats b/test/cases/search.bats index 132240a..59fabdd 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -25,6 +25,18 @@ [ "$output" == $'\"bar\"\n\"x\"' ] } +@test "Test recursive accumulate mode for nested lists" { + output=$(echo '{"foo": ["a"]}{"foo": ["x"]}' | ./jpp -a -c @) + echo "$output" + [ "$output" == '{"foo":["a","x"]}' ] +} + +@test "Test recursive accumulate mode for nested lists" { + output=$(echo '["a"]["x"]' | ./jpp -a -c @) + echo "$output" + [ "$output" == '["a","x"]' ] +} + @test "Can search subexpr expression" { output=$(echo '{"foo": {"bar": "baz"}}' | ./jp foo.bar) [ "$output" == "\"baz\"" ] From a8ea7c998c07baafd8f239cfbe6a418619e5e01f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 14 Jun 2021 22:10:50 -0700 Subject: [PATCH 07/17] jpp: version 0.1.3.1 --- cmd/jpp/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 5d8d280..07b68af 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -11,7 +11,7 @@ import ( "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" ) -const version = "0.1.3" +const version = "0.1.3.1" func main() { app := cli.NewApp() From 0abe226af789977087407929fba0e4cc85f9c5a1 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 15 Jun 2021 14:31:55 -0700 Subject: [PATCH 08/17] jpp: fix --accumulate array merge to coalesce duplicates from different nested lists Fixes: e7989df10564 ("jpp: Add --accumulate, -a option which accumulates all output objects into a single recursively merged object") --- cmd/jpp/main.go | 96 +++++++++++++++++++++++++++++++++++++++++- test/cases/search.bats | 12 ++++++ 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 07b68af..09090cd 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -1,17 +1,19 @@ package main import ( + "bytes" "encoding/json" "fmt" "io" "io/ioutil" "os" + "reflect" "github.com/jmespath/jp/Godeps/_workspace/src/github.com/codegangsta/cli" "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" ) -const version = "0.1.3.1" +const version = "0.1.3.2" func main() { app := cli.NewApp() @@ -251,7 +253,9 @@ func merge1(x1, x2 interface{}) interface{} { result = append(result, element) } for _, element := range x1 { - result = append(result, element) + if !contains(result, element) { + result = append(result, element) + } } return result case nil: @@ -264,3 +268,91 @@ func merge1(x1, x2 interface{}) interface{} { return x1 } +func equal(lhs interface{}, rhs interface{}) bool { + switch lhs := lhs.(type) { + case nil: + switch rhs.(type) { + case nil: + return true + } + return false + + case string: + switch rhs := rhs.(type) { + case string: + if lhs == rhs { + return true + } + } + return false + + case int: + switch rhs := rhs.(type) { + case int: + if lhs == rhs { + return true + } + } + return false + + case float32: + switch rhs := rhs.(type) { + case float32: + if lhs == rhs { + return true + } + } + return false + + case float64: + switch rhs := rhs.(type) { + case float64: + if lhs == rhs { + return true + } + } + return false + default: + panic(fmt.Sprintf("unhandled type comparison: %s vs %s", reflect.TypeOf(lhs), reflect.TypeOf(rhs))) + } +} + +func contains(values []interface{}, value interface{}) bool { + + valueData, err := json.Marshal(value); if err != nil { + panic(err) + } + + for _, v := range values { + switch v := v.(type) { + case map[string]interface{}: + switch value.(type) { + case map[string]interface{}: + data, err := json.Marshal(v); if err != nil { + panic(err) + } + if bytes.Compare(valueData, data) == 0 { + return true + } + } + + case []interface{}: + switch value.(type) { + case []interface{}: + data, err := json.Marshal(v); if err != nil { + panic(err) + } + if bytes.Compare(valueData, data) == 0 { + return true + } + } + + default: + if equal(v, value) { + return true + } + } + } + + return false +} diff --git a/test/cases/search.bats b/test/cases/search.bats index 59fabdd..6e4f887 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -37,6 +37,18 @@ [ "$output" == '["a","x"]' ] } +@test "Test that recursive accumulate mode coalesces duplicates from different nested lists" { + output=$(echo '{"foo": ["a", "a"]}{"foo": ["a"]}' | ./jpp -a -c @) + echo "$output" + [ "$output" == '{"foo":["a","a"]}' ] +} + +@test "Test that recursive accumulate mode preserves duplicates from the same nested list" { + output=$(echo '{"foo": ["a", "a"]}{"foo": ["a", "b"]}' | ./jpp -a -c @) + echo "$output" + [ "$output" == '{"foo":["a","a","b"]}' ] +} + @test "Can search subexpr expression" { output=$(echo '{"foo": {"bar": "baz"}}' | ./jp foo.bar) [ "$output" == "\"baz\"" ] From 74c0bbd7ccd1d325a0d2b12ff18251c431fd0636 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jun 2021 09:15:59 -0700 Subject: [PATCH 09/17] jpp: default to the identity expression @ if no expression is given --- cmd/jpp/main.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 09090cd..e3429f7 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -19,7 +19,7 @@ func main() { app := cli.NewApp() app.Name = "jpp" app.Version = version - app.Usage = "jpp [] " + app.Usage = "jpp [] [expression]" app.Author = "" app.Email = "" app.Flags = []cli.Flag{ @@ -77,9 +77,12 @@ func runMain(c *cli.Context) int { } } else { if len(c.Args()) == 0 { - return errMsg("Must provide at least one argument.") + expression = "@" + } else if len(c.Args()) > 1 { + return errMsg("Must not provide more than one argument.") + } else { + expression = c.Args()[0] } - expression = c.Args()[0] } if c.Bool("ast") { parser := jmespath.NewParser() From b025412072e6fa1029a5ebc1be92915978ef4813 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jun 2021 09:00:07 -0700 Subject: [PATCH 10/17] jpp: Add --read-raw, -R bool flag like jq has --- cmd/jpp/main.go | 52 ++++++++++++++++++++++++++++++++++++------ test/cases/search.bats | 18 +++++++++++++++ 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index e3429f7..b442fdb 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "bufio" "encoding/json" "fmt" "io" @@ -39,6 +40,10 @@ func main() { Name: "expr-file, e", Usage: "Read JMESPath expression from the specified file.", }, + cli.BoolFlag{ + Name: "read-raw, R", + Usage: "Read raw string input and box it as JSON strings.", + }, cli.BoolFlag{ Name: "slurp, s", Usage: "Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.", @@ -100,22 +105,41 @@ func runMain(c *cli.Context) int { return 0 } var jsonParser *json.Decoder + var f *os.File + var rawInput *bufio.Scanner + var rawInputBuffer []byte if c.String("filename") != "" { - f, err := os.Open(c.String("filename")) + var err error + f, err = os.Open(c.String("filename")) if err != nil { return errMsg("Error opening input file: %s", err) } - jsonParser = json.NewDecoder(f) + } else { + f = os.Stdin + } + if c.Bool("read-raw") && c.Bool("slurp") { + var err error + rawInputBuffer, err = ioutil.ReadAll(f) + if err != nil { + return errMsg("Error reading input file: %s", err) + } + } else if c.Bool("read-raw") { + rawInput = bufio.NewScanner(f) } else { - jsonParser = json.NewDecoder(os.Stdin) + jsonParser = json.NewDecoder(f) } var slurpInput []interface{} - if c.Bool("slurp") { + if c.Bool("slurp") && !c.Bool("read-raw") { for { var element interface{} - if err := jsonParser.Decode(&element); err == io.EOF { + if rawInput != nil { + if !rawInput.Scan() { + break + } + element = rawInput.Text() + } else if err := jsonParser.Decode(&element); err == io.EOF { break } else if err != nil { errMsg("Error parsing input json: %s\n", err) @@ -134,7 +158,18 @@ func runMain(c *cli.Context) int { var input interface{} var err error if c.Bool("slurp") { - input = slurpInput + eof = true + if c.Bool("read-raw") { + input = string(rawInputBuffer) + } else { + input = slurpInput + } + } else if rawInput != nil { + if !rawInput.Scan() { + eof = true + break + } + input = rawInput.Text() } else if err = jsonParser.Decode(&input); err == io.EOF { eof = true break @@ -161,6 +196,9 @@ func runMain(c *cli.Context) int { return 2 } } + if c.Bool("slurp") { + break + } } else { break } @@ -168,7 +206,7 @@ func runMain(c *cli.Context) int { if c.Bool("accumulate") { result = accumulator - } else if eof { + } else if eof && !c.Bool("slurp") { break } diff --git a/test/cases/search.bats b/test/cases/search.bats index 6e4f887..0af4ced 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -49,6 +49,24 @@ [ "$output" == '{"foo":["a","a","b"]}' ] } +@test "Test raw string input" { + output=$(echo 'hello world' | ./jpp -R -a -c @) + echo "$output" + [ "$output" == '"hello world"' ] +} + +@test "Test multi-line raw string input" { + output=$(printf -- '%s\n' 'line '{1..3} | ./jpp -R -c @) + echo "$output" + [ "$output" == $'"line 1"\n"line 2"\n"line 3"\n' ] +} + +@test "Test multi-line raw string input slurp" { + output=$(printf -- '%s\n' 'line '{1..3} | ./jpp -R -s -c @) + echo "$output" + [ "$output" == '"line 1\nline 2\nline 3\n"' ] +} + @test "Can search subexpr expression" { output=$(echo '{"foo": {"bar": "baz"}}' | ./jp foo.bar) [ "$output" == "\"baz\"" ] From 39fd7916d58b950ce1dd706978c60f10e1525a9c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jun 2021 12:10:59 -0700 Subject: [PATCH 11/17] jpp: Add --raw, -r bool flag like jq has (an alias for unquoted) --- cmd/jpp/main.go | 9 +++++++-- test/cases/search.bats | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index b442fdb..87734a0 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -14,7 +14,7 @@ import ( "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" ) -const version = "0.1.3.2" +const version = "0.1.3.3" func main() { app := cli.NewApp() @@ -40,6 +40,10 @@ func main() { Name: "expr-file, e", Usage: "Read JMESPath expression from the specified file.", }, + cli.BoolFlag{ + Name: "raw, r", + Usage: "If the final result is a string, it will be printed without quotes (an alias for unquoted).", + }, cli.BoolFlag{ Name: "read-raw, R", Usage: "Read raw string input and box it as JSON strings.", @@ -211,7 +215,8 @@ func runMain(c *cli.Context) int { } converted, isString := result.(string) - if c.Bool("unquoted") && isString { + quoted := ! ((c.Bool("unquoted") || c.Bool("raw")) && isString) + if !quoted { os.Stdout.WriteString(converted) } else { var toJSON []byte diff --git a/test/cases/search.bats b/test/cases/search.bats index 0af4ced..c74410a 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -55,6 +55,18 @@ [ "$output" == '"hello world"' ] } +@test "Test raw string input" { + output=$(echo 'hello world' | ./jpp -R -r @) + echo "$output" + [ "$output" == 'hello world' ] +} + +@test "Test raw string input" { + output=$(echo 'hello world' | ./jpp -R -u @) + echo "$output" + [ "$output" == 'hello world' ] +} + @test "Test multi-line raw string input" { output=$(printf -- '%s\n' 'line '{1..3} | ./jpp -R -c @) echo "$output" From fbd178fb35f5b859ebc34a8e65fe7ebe5389b3ce Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jun 2021 21:10:27 -0700 Subject: [PATCH 12/17] jpp: rename --read-raw to --raw-input for consistency with jq --- cmd/jpp/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 87734a0..cc0ffcf 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -45,7 +45,7 @@ func main() { Usage: "If the final result is a string, it will be printed without quotes (an alias for unquoted).", }, cli.BoolFlag{ - Name: "read-raw, R", + Name: "raw-input, R", Usage: "Read raw string input and box it as JSON strings.", }, cli.BoolFlag{ @@ -122,20 +122,20 @@ func runMain(c *cli.Context) int { f = os.Stdin } - if c.Bool("read-raw") && c.Bool("slurp") { + if c.Bool("raw-input") && c.Bool("slurp") { var err error rawInputBuffer, err = ioutil.ReadAll(f) if err != nil { return errMsg("Error reading input file: %s", err) } - } else if c.Bool("read-raw") { + } else if c.Bool("raw-input") { rawInput = bufio.NewScanner(f) } else { jsonParser = json.NewDecoder(f) } var slurpInput []interface{} - if c.Bool("slurp") && !c.Bool("read-raw") { + if c.Bool("slurp") && !c.Bool("raw-input") { for { var element interface{} if rawInput != nil { @@ -163,7 +163,7 @@ func runMain(c *cli.Context) int { var err error if c.Bool("slurp") { eof = true - if c.Bool("read-raw") { + if c.Bool("raw-input") { input = string(rawInputBuffer) } else { input = slurpInput From 9caa261b30d3440cd930f76c938fae92244d9c85 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jun 2021 21:48:33 -0700 Subject: [PATCH 13/17] jpp: Add --unbox, -u flag (and drop --unquoted to reduce clutter) If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode. See: https://github.com/stedolan/jq/issues/878 --- cmd/jpp/main.go | 54 ++++++++++++++++++++++++++++++------------ test/cases/search.bats | 6 +++++ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index cc0ffcf..92c9d95 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -42,7 +42,7 @@ func main() { }, cli.BoolFlag{ Name: "raw, r", - Usage: "If the final result is a string, it will be printed without quotes (an alias for unquoted).", + Usage: "If the final result is a string, it will be printed without quotes.", }, cli.BoolFlag{ Name: "raw-input, R", @@ -53,8 +53,8 @@ func main() { Usage: "Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.", }, cli.BoolFlag{ - Name: "unquoted, u", - Usage: "If the final result is a string, it will be printed without quotes.", + Name: "unbox, u", + Usage: "If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode.", }, cli.BoolFlag{ Name: "ast", @@ -215,24 +215,32 @@ func runMain(c *cli.Context) int { } converted, isString := result.(string) - quoted := ! ((c.Bool("unquoted") || c.Bool("raw")) && isString) + quoted := ! (c.Bool("raw") && isString) if !quoted { os.Stdout.WriteString(converted) } else { - var toJSON []byte - var err error - if c.Bool("compact") { - toJSON, err = json.Marshal(result) - } else { - toJSON, err = json.MarshalIndent(result, "", " ") + + var unboxed bool + if c.Bool("unbox") { + switch result := result.(type) { + case []interface{}: + unboxed = true + for _, element := range result { + if err := outputResult(c, element); err != nil { + errMsg("Error marshalling result to JSON: %s\n", err) + return 3 + } + } + } } - if err != nil { - errMsg("Error marshalling result to JSON: %s\n", err) - return 3 + + if !unboxed { + if err := outputResult(c, result); err != nil { + errMsg("Error marshalling result to JSON: %s\n", err) + return 3 + } } - os.Stdout.Write(toJSON) } - os.Stdout.WriteString("\n") if eof || c.Bool("accumulate") || c.Bool("slurp") { break } @@ -240,6 +248,22 @@ func runMain(c *cli.Context) int { return 0 } +func outputResult(c *cli.Context, result interface{}) error { + var toJSON []byte + var err error + if c.Bool("compact") { + toJSON, err = json.Marshal(result) + } else { + toJSON, err = json.MarshalIndent(result, "", " ") + } + if err != nil { + return err + } + os.Stdout.Write(toJSON) + os.Stdout.WriteString("\n") + return nil +} + // The following merge and merge1 functions come from the // golang playground link posted by Roger Peppe in this // "Recursively merge JSON structures" thread: diff --git a/test/cases/search.bats b/test/cases/search.bats index c74410a..e58ac49 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -37,6 +37,12 @@ [ "$output" == '["a","x"]' ] } +@test "Test recursive accumulate mode for nested lists" { + output=$(echo '["a"]["x"]' | ./jpp -a -c -u @) + echo "$output" + [ "$output" == $'"a"\n"x"' ] +} + @test "Test that recursive accumulate mode coalesces duplicates from different nested lists" { output=$(echo '{"foo": ["a", "a"]}{"foo": ["a"]}' | ./jpp -a -c @) echo "$output" From f574aa57ce4f68fc3d6892302dc6e69bf3640fc6 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jun 2021 21:57:56 -0700 Subject: [PATCH 14/17] jpp: rename --raw to --raw-output for consistency with jq --- cmd/jpp/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 92c9d95..fd432dd 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -14,7 +14,7 @@ import ( "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" ) -const version = "0.1.3.3" +const version = "0.1.3.4" func main() { app := cli.NewApp() @@ -41,7 +41,7 @@ func main() { Usage: "Read JMESPath expression from the specified file.", }, cli.BoolFlag{ - Name: "raw, r", + Name: "raw-output, r", Usage: "If the final result is a string, it will be printed without quotes.", }, cli.BoolFlag{ @@ -215,7 +215,7 @@ func runMain(c *cli.Context) int { } converted, isString := result.(string) - quoted := ! (c.Bool("raw") && isString) + quoted := ! (c.Bool("raw-output") && isString) if !quoted { os.Stdout.WriteString(converted) } else { From ba7ce1cb6b4de4b0936fc18caebddd14aad90cb6 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 17 Jun 2021 00:18:42 -0700 Subject: [PATCH 15/17] jpp: fix --raw-output to apply to output strings from --unbox --- cmd/jpp/main.go | 65 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index fd432dd..51d4790 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -14,7 +14,7 @@ import ( "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" ) -const version = "0.1.3.4" +const version = "0.1.3.5" func main() { app := cli.NewApp() @@ -214,33 +214,28 @@ func runMain(c *cli.Context) int { break } - converted, isString := result.(string) - quoted := ! (c.Bool("raw-output") && isString) - if !quoted { - os.Stdout.WriteString(converted) - } else { - var unboxed bool - if c.Bool("unbox") { - switch result := result.(type) { - case []interface{}: - unboxed = true - for _, element := range result { - if err := outputResult(c, element); err != nil { - errMsg("Error marshalling result to JSON: %s\n", err) - return 3 - } + var unboxed bool + if c.Bool("unbox") { + switch result := result.(type) { + case []interface{}: + unboxed = true + for _, element := range result { + if err := outputResult(c, element); err != nil { + errMsg("Error marshalling result to JSON: %s\n", err) + return 3 } - } + } } - - if !unboxed { - if err := outputResult(c, result); err != nil { - errMsg("Error marshalling result to JSON: %s\n", err) - return 3 - } + } + + if !unboxed { + if err := outputResult(c, result); err != nil { + errMsg("Error marshalling result to JSON: %s\n", err) + return 3 } } + if eof || c.Bool("accumulate") || c.Bool("slurp") { break } @@ -249,17 +244,23 @@ func runMain(c *cli.Context) int { } func outputResult(c *cli.Context, result interface{}) error { - var toJSON []byte - var err error - if c.Bool("compact") { - toJSON, err = json.Marshal(result) + converted, isString := result.(string) + quoted := ! (c.Bool("raw-output") && isString) + if quoted { + var toJSON []byte + var err error + if c.Bool("compact") { + toJSON, err = json.Marshal(result) + } else { + toJSON, err = json.MarshalIndent(result, "", " ") + } + if err != nil { + return err + } + os.Stdout.Write(toJSON) } else { - toJSON, err = json.MarshalIndent(result, "", " ") - } - if err != nil { - return err + os.Stdout.WriteString(converted) } - os.Stdout.Write(toJSON) os.Stdout.WriteString("\n") return nil } From 618abea121316333a25411816b5ea6d906e58654 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 17 Jun 2021 01:22:19 -0700 Subject: [PATCH 16/17] jpp: update go-jmespath and urfave/cli dependencies via go modules --- cmd/jpp/main.go | 6 +++--- go.mod | 10 ++++++++++ go.sum | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index 51d4790..fc80dfc 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -10,11 +10,11 @@ import ( "os" "reflect" - "github.com/jmespath/jp/Godeps/_workspace/src/github.com/codegangsta/cli" - "github.com/jmespath/jp/Godeps/_workspace/src/github.com/jmespath/go-jmespath" + "github.com/jmespath/go-jmespath" + "github.com/urfave/cli" ) -const version = "0.1.3.5" +const version = "0.1.3.6" func main() { app := cli.NewApp() diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3c8f81f --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/jmespath/jp + +go 1.16 + +replace github.com/jmespath/jp => ./ + +require ( + github.com/jmespath/go-jmespath v0.4.0 + github.com/urfave/cli v1.22.5 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..fe4e65d --- /dev/null +++ b/go.sum @@ -0,0 +1,18 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= +github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 6a504e8305e06a5f96c4c39f5f0864bc54689d26 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 17 Jun 2021 13:00:36 -0700 Subject: [PATCH 17/17] jpp: convert cli to spf13/cobra and re-add --unquoted (a short -u means --unbox now) $ ./jpp --help An extended superset of the jp CLI for JMESPath Usage: jpp [] [expression] [flags] Flags: -a, --accumulate Accumulate all output objects into a single recursively merged output object. --ast Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes. -c, --compact Produce compact JSON output that omits nonessential whitespace. -e, --expr-file string Read JMESPath expression from the specified file. -f, --filename string Read input JSON from a file instead of stdin. -h, --help show usage and exit -R, --raw-input Read raw string input and box it as JSON strings. -r, --raw-output If the final result is a string, it will be printed without quotes (an alias for --unquoted). -s, --slurp Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array. -u, --unbox If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode. --unquoted If the final result is a string, it will be printed without quotes. --- cmd/jpp/main.go | 261 ++++++++++++++++++++++++-------------- go.mod | 2 +- go.sum | 282 +++++++++++++++++++++++++++++++++++++++++ test/cases/search.bats | 2 +- 4 files changed, 449 insertions(+), 98 deletions(-) diff --git a/cmd/jpp/main.go b/cmd/jpp/main.go index fc80dfc..96219dc 100644 --- a/cmd/jpp/main.go +++ b/cmd/jpp/main.go @@ -11,63 +11,107 @@ import ( "reflect" "github.com/jmespath/go-jmespath" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) -const version = "0.1.3.6" +const version = "0.1.3.7" + +type JppConfig struct { + Accumulate bool `json:"accumulate"` + Ast bool `json:"ast"` + Compact bool `json:"compact"` + ExprFile string `json:"expr-file"` + Filename string `json:"filename"` + RawInput bool `json:"raw-input"` + RawOutput bool `json:"raw-output"` + Slurp bool `json:"slurp"` + Unbox bool `json:"unbox"` +} -func main() { - app := cli.NewApp() - app.Name = "jpp" - app.Version = version - app.Usage = "jpp [] [expression]" - app.Author = "" - app.Email = "" - app.Flags = []cli.Flag{ - cli.BoolFlag{ - Name: "accumulate, a", - Usage: "Accumulate all output objects into a single recursively merged output object.", - }, - cli.BoolFlag{ - Name: "compact, c", - Usage: "Produce compact JSON output that omits nonessential whitespace.", - }, - cli.StringFlag{ - Name: "filename, f", - Usage: "Read input JSON from a file instead of stdin.", - }, - cli.StringFlag{ - Name: "expr-file, e", - Usage: "Read JMESPath expression from the specified file.", - }, - cli.BoolFlag{ - Name: "raw-output, r", - Usage: "If the final result is a string, it will be printed without quotes.", - }, - cli.BoolFlag{ - Name: "raw-input, R", - Usage: "Read raw string input and box it as JSON strings.", - }, - cli.BoolFlag{ - Name: "slurp, s", - Usage: "Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.", - }, - cli.BoolFlag{ - Name: "unbox, u", - Usage: "If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode.", - }, - cli.BoolFlag{ - Name: "ast", - Usage: "Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes.", - }, +func JppCommand() *cobra.Command { + var jppCmd = &cobra.Command{ + Use: "jpp [] [expression]", + Short: "An extended superset of the jp CLI for JMESPath", + Args: cobra.MaximumNArgs(1), + RunE: JppCobraLaunchMain, } - app.Action = runMainAndExit - app.Run(os.Args) + flags := jppCmd.PersistentFlags() + + flags.BoolP( + "accumulate", + "a", + false, + "Accumulate all output objects into a single recursively merged output object.", + ) + flags.Bool( + "ast", + false, + "Only print the AST of the parsed expression. Do not rely on this output, only useful for debugging purposes.", + ) + flags.BoolP( + "compact", + "c", + false, + "Produce compact JSON output that omits nonessential whitespace.", + ) + flags.StringP( + "filename", + "f", + "", + "Read input JSON from a file instead of stdin.", + ) + flags.StringP( + "expr-file", + "e", + "", + "Read JMESPath expression from the specified file.", + ) + flags.BoolP( + "raw-output", + "r", + false, + "If the final result is a string, it will be printed without quotes (an alias for --unquoted).", + ) + flags.BoolP( + "raw-input", + "R", + false, + "Read raw string input and box it as JSON strings.", + ) + flags.BoolP( + "slurp", + "s", + false, + "Read one or more input JSON objects into an array and apply the JMESPath expression to the resulting array.", + ) + flags.BoolP( + "unbox", + "u", + false, + "If the final result is a list, unbox it into a stream of output objects that is suitable for consumption by --slurp mode.", + ) + flags.Bool( + "unquoted", + false, + "If the final result is a string, it will be printed without quotes.", + ) + flags.BoolP( + "help", + "h", + false, + "show usage and exit", + ) + + return jppCmd } -func runMainAndExit(c *cli.Context) { - os.Exit(runMain(c)) +func main() { + jppCmd := JppCommand() + jppCmd.SetArgs(os.Args[1:]) + if err := jppCmd.Execute(); err != nil { + os.Exit(errMsg(err.Error())) + } } func errMsg(msg string, a ...interface{}) int { @@ -76,66 +120,97 @@ func errMsg(msg string, a ...interface{}) int { return 1 } -func runMain(c *cli.Context) int { +func MustGetString(cmd *cobra.Command, name string) string { + value, err := cmd.Flags().GetString(name) + if err != nil { + panic(err) + } + return value +} + +func MustGetBool(cmd *cobra.Command, name string) bool { + value, err := cmd.Flags().GetBool(name) + if err != nil { + panic(err) + } + return value +} + +func JppCobraLaunchMain(cmd *cobra.Command, args []string) error { + config := &JppConfig{ + MustGetBool(cmd, "accumulate"), + MustGetBool(cmd, "ast"), + MustGetBool(cmd, "compact"), + MustGetString(cmd, "expr-file"), + MustGetString(cmd, "filename"), + MustGetBool(cmd, "raw-input"), + MustGetBool(cmd, "raw-output") || MustGetBool(cmd, "unquoted"), + MustGetBool(cmd, "slurp"), + MustGetBool(cmd, "unbox"), + } + return JppMain(config, args) +} + +func JppMain(config *JppConfig, args []string) error { var expression string - if c.String("expr-file") != "" { - byteExpr, err := ioutil.ReadFile(c.String("expr-file")) + if config.ExprFile != "" { + byteExpr, err := ioutil.ReadFile(config.ExprFile) expression = string(byteExpr) if err != nil { - return errMsg("Error opening expression file: %s", err) + return fmt.Errorf("Error opening expression file: %w", err) } } else { - if len(c.Args()) == 0 { + if len(args) == 0 { expression = "@" - } else if len(c.Args()) > 1 { - return errMsg("Must not provide more than one argument.") + } else if len(args) > 1 { + return fmt.Errorf("Must not provide more than one argument.") } else { - expression = c.Args()[0] + expression = args[0] } } - if c.Bool("ast") { + if config.Ast { parser := jmespath.NewParser() parsed, err := parser.Parse(expression) if err != nil { if syntaxError, ok := err.(jmespath.SyntaxError); ok { - return errMsg("%s\n%s\n", + fmt.Errorf("%s\n%s\n", syntaxError, syntaxError.HighlightLocation()) } - return errMsg("%s", err) + return err } fmt.Println("") fmt.Printf("%s\n", parsed) - return 0 + return nil } var jsonParser *json.Decoder var f *os.File var rawInput *bufio.Scanner var rawInputBuffer []byte - if c.String("filename") != "" { + if config.Filename != "" { var err error - f, err = os.Open(c.String("filename")) + f, err = os.Open(config.Filename) if err != nil { - return errMsg("Error opening input file: %s", err) + fmt.Errorf("Error opening input file: %w", err) } } else { f = os.Stdin } - if c.Bool("raw-input") && c.Bool("slurp") { + if config.RawInput && config.Slurp { var err error rawInputBuffer, err = ioutil.ReadAll(f) if err != nil { - return errMsg("Error reading input file: %s", err) + fmt.Errorf("Error reading input file: %w", err) } - } else if c.Bool("raw-input") { + } else if config.RawInput { rawInput = bufio.NewScanner(f) } else { jsonParser = json.NewDecoder(f) } var slurpInput []interface{} - if c.Bool("slurp") && !c.Bool("raw-input") { + if config.Slurp && !config.RawInput { for { var element interface{} if rawInput != nil { @@ -146,8 +221,7 @@ func runMain(c *cli.Context) int { } else if err := jsonParser.Decode(&element); err == io.EOF { break } else if err != nil { - errMsg("Error parsing input json: %s\n", err) - return 2 + return fmt.Errorf("Error parsing input json: %w", err) } slurpInput = append(slurpInput, element) } @@ -161,9 +235,9 @@ func runMain(c *cli.Context) int { for { var input interface{} var err error - if c.Bool("slurp") { + if config.Slurp { eof = true - if c.Bool("raw-input") { + if config.RawInput { input = string(rawInputBuffer) } else { input = slurpInput @@ -178,29 +252,27 @@ func runMain(c *cli.Context) int { eof = true break } else if err != nil { - errMsg("Error parsing input json: %s\n", err) - return 2 + return fmt.Errorf("Error parsing input json: %w", err) } result, err = jmespath.Search(expression, input) if err != nil { if syntaxError, ok := err.(jmespath.SyntaxError); ok { - return errMsg("%s\n%s\n", + return fmt.Errorf("%s\n%s\n", syntaxError, syntaxError.HighlightLocation()) } - return errMsg("Error evaluating JMESPath expression: %s", err) + return fmt.Errorf("Error evaluating JMESPath expression: %w", err) } - if c.Bool("accumulate") { + if config.Accumulate { if accumulator == nil { accumulator = result } else { accumulator, err = merge(result, accumulator); if err != nil { - errMsg("Error merging output json: %s\n", err) - return 2 + return fmt.Errorf("Error merging output json: %w", err) } } - if c.Bool("slurp") { + if config.Slurp { break } } else { @@ -208,48 +280,45 @@ func runMain(c *cli.Context) int { } } - if c.Bool("accumulate") { + if config.Accumulate { result = accumulator - } else if eof && !c.Bool("slurp") { + } else if eof && !config.Slurp { break } - var unboxed bool - if c.Bool("unbox") { + if config.Unbox { switch result := result.(type) { case []interface{}: unboxed = true for _, element := range result { - if err := outputResult(c, element); err != nil { - errMsg("Error marshalling result to JSON: %s\n", err) - return 3 + if err := OutputResult(element, config); err != nil { + return fmt.Errorf("Error marshalling result to JSON: %w", err) } } } } if !unboxed { - if err := outputResult(c, result); err != nil { - errMsg("Error marshalling result to JSON: %s\n", err) - return 3 + if err := OutputResult(result, config); err != nil { + return fmt.Errorf("Error marshalling result to JSON: %w", err) } } - if eof || c.Bool("accumulate") || c.Bool("slurp") { + if eof || config.Accumulate || config.Slurp { break } } - return 0 + return nil } -func outputResult(c *cli.Context, result interface{}) error { +func OutputResult(result interface{}, config *JppConfig) error { converted, isString := result.(string) - quoted := ! (c.Bool("raw-output") && isString) + quoted := ! (config.RawOutput && isString) if quoted { var toJSON []byte var err error - if c.Bool("compact") { + if config.Compact { toJSON, err = json.Marshal(result) } else { toJSON, err = json.MarshalIndent(result, "", " ") diff --git a/go.mod b/go.mod index 3c8f81f..93a4df2 100644 --- a/go.mod +++ b/go.mod @@ -6,5 +6,5 @@ replace github.com/jmespath/jp => ./ require ( github.com/jmespath/go-jmespath v0.4.0 - github.com/urfave/cli v1.22.5 + github.com/spf13/cobra v1.1.3 ) diff --git a/go.sum b/go.sum index fe4e65d..0e7c09c 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,300 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/test/cases/search.bats b/test/cases/search.bats index e58ac49..6ed78b7 100644 --- a/test/cases/search.bats +++ b/test/cases/search.bats @@ -68,7 +68,7 @@ } @test "Test raw string input" { - output=$(echo 'hello world' | ./jpp -R -u @) + output=$(echo 'hello world' | ./jpp -R --unquoted @) echo "$output" [ "$output" == 'hello world' ] }