Skip to content

Commit

Permalink
new -D flag for deleting value
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Oct 20, 2016
1 parent 8444861 commit 868180e
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

VERSION="0.1.0"
VERSION="0.1.1"
PROTECTED_MODE="no"

export GO15VENDOREXPERIMENT=1
Expand Down
13 changes: 11 additions & 2 deletions cmd/jsoned/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
version = "0.0.1"
tag = "jsoned - JSON Stream Editor " + version
usage = `
usage: jsoned [-v value] [-s] [-i infile] [-o outfile] keypath
usage: jsoned [-v value] [-s] [-D] [-i infile] [-o outfile] keypath
examples: jsoned keypath read value from stdin
or: jsoned -i infile keypath read value from infile
Expand All @@ -24,6 +24,7 @@ examples: jsoned keypath read value from stdin
options:
-v value Edit JSON key path value
-D Delete the value at the specified key path
-i infile Use input file instead of stdin
-o outfile Use output file instead of stdout
-r Use raw values, otherwise types are auto-detected
Expand All @@ -38,6 +39,7 @@ type args struct {
outfile *string
value *string
raw bool
del bool
keypath string
}

Expand Down Expand Up @@ -82,6 +84,8 @@ func parseArgs() args {
}
case "-r":
a.raw = true
case "-D":
a.del = true
case "-h", "--help", "-?":
help()
}
Expand All @@ -107,7 +111,12 @@ func main() {
if err != nil {
goto fail
}
if a.value != nil {
if a.del {
outb, err = sjson.DeleteBytes(input, a.keypath)
if err != nil {
goto fail
}
} else if a.value != nil {
raw := a.raw
val := *a.value
if !raw {
Expand Down
22 changes: 0 additions & 22 deletions resources/vendor.sh

This file was deleted.

33 changes: 30 additions & 3 deletions vendor/github.com/tidwall/sjson/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 128 additions & 26 deletions vendor/github.com/tidwall/sjson/sjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 868180e

Please sign in to comment.