Skip to content

Commit

Permalink
Add option to ignore case
Browse files Browse the repository at this point in the history
  • Loading branch information
jastBytes committed Aug 10, 2020
1 parent ccf521f commit f24105b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Usage:
jp [flags]
Flags:
-h, --help help for jp
-k, --key string Key to search for
-t, --show-type If enabled, will show the type of the value for found path
-v, --show-value If enabled, will show the value for found path
-h, --help help for jp
-i, --ignore-case If enabled, will ignores case when matching key
-k, --key string Key to search for
-t, --show-type If enabled, will show the type of the value for found path
-v, --show-value If enabled, will show the value for found path
```

## Example
Expand All @@ -21,11 +22,13 @@ Flags:
$ kubectl get node node01 -ojson | jp -k osImage
.status.nodeInfo.osImage
$ kubectl get node node01 -ojson | jp -k osImage -v
.status.nodeInfo.osImage:Flatcar Container Linux by Kinvolk 2512.2.0 (Oklo)
.status.nodeInfo.osImage:Flatcar Container Linux
$ kubectl get node node01 -ojson | jp -k osImage -v -t
.status.nodeInfo.osImage:Flatcar Container Linux by Kinvolk 2512.2.0 (Oklo):string
.status.nodeInfo.osImage:Flatcar Container Linux:string
$ kubectl get node node01 -ojson | jp -k osImage -t
.status.nodeInfo.osImage:string
kubectl get node node01 -ojson | ./jp.linux -k containerruntimeversion -v -i
.status.nodeInfo.containerRuntimeVersion:docker://47.1.1
```

## Releases
Expand Down
11 changes: 7 additions & 4 deletions cmd/jp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import (
"flag"
"fmt"
"os"
"strings"

"gopkg.in/spf13/cobra.v0"
)

var (
key string
showValue bool
showType bool
key string
showValue bool
showType bool
ignoreCase bool
)

var jpCmd = &cobra.Command{
Expand Down Expand Up @@ -55,14 +57,15 @@ func init() {
flags.StringVarP(&key, "key", "k", "", "Key to search for")
flags.BoolVarP(&showValue, "show-value", "v", false, "If enabled, will show the value for found path")
flags.BoolVarP(&showType, "show-type", "t", false, "If enabled, will show the type of the value for found path")
flags.BoolVarP(&ignoreCase, "ignore-case", "i", false, "If enabled, will ignores case when matching key")
}

func printPaths(v interface{}, key, path string) {
switch v := v.(type) {
case map[string]interface{}:
for mk, mv := range v {
p := path + "." + mk
if mk == key {
if (ignoreCase && strings.EqualFold(mk, key)) || mk == key {
fmt.Print(p)
if showValue {
fmt.Printf(":%v", mv)
Expand Down

0 comments on commit f24105b

Please sign in to comment.