Skip to content

Commit 95398e3

Browse files
committed
Add permissive option to jsoncols and jsonrange, updated release process, bumped Version
1 parent 462c80f commit 95398e3

File tree

6 files changed

+31
-693
lines changed

6 files changed

+31
-693
lines changed

cmds/jsoncols/jsoncols.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// Caltech Library Packages
1919
"github.com/caltechlibrary/cli"
2020
"github.com/caltechlibrary/datatools"
21-
"github.com/caltechlibrary/datatools/dotpath"
21+
"github.com/caltechlibrary/dotpath"
2222
)
2323

2424
var (
@@ -87,6 +87,7 @@ Would yield
8787
runInteractive bool
8888
delimiter = ","
8989
expressions []string
90+
permissive bool
9091
)
9192

9293
func init() {
@@ -104,6 +105,7 @@ func init() {
104105
flag.BoolVar(&runInteractive, "r", false, "run interactively")
105106
flag.BoolVar(&runInteractive, "repl", false, "run interactively")
106107
flag.StringVar(&delimiter, "d", delimiter, "set the delimiter for multi-field output")
108+
flag.BoolVar(&permissive, "permissive", false, "suppress error messages")
107109
}
108110

109111
func main() {
@@ -167,7 +169,12 @@ func main() {
167169
fmt.Fprintf(os.Stderr, "%s\n", err)
168170
os.Exit(1)
169171
}
172+
// JSON Decode our document
170173
data, err := dotpath.JSONDecode(buf)
174+
if err != nil {
175+
fmt.Fprintf(os.Stderr, "%s\n", err)
176+
os.Exit(1)
177+
}
171178

172179
// For each dotpath expression return a result
173180
for i, qry := range expressions {
@@ -178,23 +185,24 @@ func main() {
178185
fmt.Fprintf(out, "%s", buf)
179186
} else {
180187
result, err := dotpath.Eval(qry, data)
181-
if err != nil {
188+
if err == nil {
189+
switch result.(type) {
190+
case string:
191+
fmt.Fprintf(out, "%s", result)
192+
case json.Number:
193+
fmt.Fprintf(out, "%s", result.(json.Number).String())
194+
default:
195+
src, err := json.Marshal(result)
196+
if err != nil {
197+
fmt.Fprintf(os.Stderr, "%s\n", err)
198+
os.Exit(1)
199+
}
200+
fmt.Fprintf(out, "%s", src)
201+
}
202+
} else if permissive == false {
182203
fmt.Fprintf(os.Stderr, "%s\n", err)
183204
os.Exit(1)
184205
}
185-
switch result.(type) {
186-
case string:
187-
fmt.Fprintf(out, "%s", result)
188-
case json.Number:
189-
fmt.Fprintf(out, "%s", result.(json.Number).String())
190-
default:
191-
src, err := json.Marshal(result)
192-
if err != nil {
193-
fmt.Fprintf(os.Stderr, "%s\n", err)
194-
os.Exit(1)
195-
}
196-
fmt.Fprintf(out, "%s", src)
197-
}
198206
}
199207
}
200208
}

cmds/jsonrange/jsonrange.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// CaltechLibrary Packages
1919
"github.com/caltechlibrary/cli"
2020
"github.com/caltechlibrary/datatools"
21-
"github.com/caltechlibrary/datatools/dotpath"
21+
"github.com/caltechlibrary/dotpath"
2222
)
2323

2424
var (
@@ -137,6 +137,7 @@ would yield
137137
showValues bool
138138
delimiter string
139139
limit int
140+
permissive bool
140141
)
141142

142143
func mapKeys(data map[string]interface{}, limit int) ([]string, error) {
@@ -242,6 +243,7 @@ func init() {
242243
flag.StringVar(&delimiter, "d", "", "set delimiter for range output")
243244
flag.StringVar(&delimiter, "delimiter", "", "set delimiter for range output")
244245
flag.IntVar(&limit, "limit", 0, "limit the number of items output")
246+
flag.BoolVar(&permissive, "permissive", false, "Suppress errors messages")
245247
}
246248

247249
func main() {
@@ -296,10 +298,13 @@ func main() {
296298
os.Exit(1)
297299
}
298300

299-
if len(buf) == 0 {
301+
if len(buf) == 0 && permissive == false {
300302
fmt.Fprintln(os.Stderr, cfg.Usage())
301303
os.Exit(1)
302304
}
305+
if len(buf) == 0 && permissive == true {
306+
os.Exit(0)
307+
}
303308

304309
var (
305310
data interface{}

datatools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
const (
37-
Version = "v0.0.8"
37+
Version = "v0.0.9"
3838

3939
LicenseText = `
4040
%s %s

dotpath/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

dotpath/dotpath.go

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)