Skip to content

Commit 4987b05

Browse files
committed
Quick Save
1 parent 0a0b555 commit 4987b05

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

cmds/jsoncols/jsoncols.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"fmt"
1414
"io/ioutil"
1515
"os"
16-
"strings"
1716

1817
// Caltech Library Packages
1918
"github.com/caltechlibrary/cli"
@@ -116,7 +115,7 @@ func main() {
116115
app.BoolVar(&runInteractive, "repl", false, "run interactively")
117116
app.BoolVar(&csvOutput, "csv", false, "output as CSV or other flat delimiter row")
118117
app.StringVar(&delimiter, "d,delimiter", delimiter, "set the delimiter for multi-field csv output")
119-
app.BoolVar(&quote, "quote", false, "if dilimiter is found in column value add quotes for non-CSV output")
118+
app.BoolVar(&quote, "quote", true, "quote strings and JSON notation")
120119

121120
// Parse Environment and Options
122121
app.Parse()
@@ -223,7 +222,7 @@ func main() {
223222
cli.ExitOnError(app.Eout, err, quiet)
224223
switch result.(type) {
225224
case string:
226-
if quote == true && strings.Contains(result.(string), delimiter) == true {
225+
if quote == true {
227226
fmt.Fprintf(app.Out, "%q", result)
228227
} else {
229228
fmt.Fprintf(app.Out, "%s", result)

demos/jsoncols/demo.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ echo ''
1313

1414
echo ' running: jsoncols -i myblob.json -d "|" .name .age'
1515
jsoncols -i myblob.json -d "|" .name .age > result2.txt
16-
echo 'expected: Doe, Jane|42'
16+
echo 'expected: "Doe, Jane"|42'
1717
echo -n ' got: '
1818
cat result2.txt
1919
echo ''
2020

2121
echo ' running: cat myblob.json | jsoncols .name .email .age'
2222
cat myblob.json | jsoncols .name .email .age > result3.txt
23-
echo 'expected: "Doe, Jane",[email protected],42'
23+
echo 'expected: "Doe, Jane","[email protected]",42'
2424
echo -n ' got: '
2525
cat result3.txt
2626
echo ''

demos/jsoncols/result2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Doe, Jane|42
1+
"Doe, Jane"|42

demos/jsoncols/result3.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"Doe, Jane",[email protected],42
1+
"Doe, Jane","[email protected]",42

test_cmds.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,19 @@ function test_findfile(){
531531

532532
function test_jsoncols(){
533533
if [ -f temp.txt ]; then rm temp.txt; fi
534-
jsoncols -i demos/jsoncols/myblob.json -o temp.txt .name
534+
bin/jsoncols -nl -i demos/jsoncols/myblob.json -o temp.txt .name
535535
assert_exists "test_jsoncols (-i, -o)" temp.txt
536536
R=$(cmp demos/jsoncols/result1.txt temp.txt)
537537
assert_empty "test_jsoncols (result1)" "$R"
538538

539539
if [ -f temp.txt ]; then rm temp.txt; fi
540-
jsoncols -i demos/jsoncols/myblob.json -d '|' .name .age > temp.txt
540+
bin/jsoncols -nl -i demos/jsoncols/myblob.json -d '|' .name .age > temp.txt
541541
assert_exists "test_jsoncols (-i, -d)" temp.txt
542542
R=$(cmp demos/jsoncols/result2.txt temp.txt)
543543
assert_empty "test_jsoncols (result2)" "$R"
544544

545545
if [ -f temp.txt ]; then rm temp.txt; fi
546-
cat demos/jsoncols/myblob.json | jsoncols .name .email .age > temp.txt
546+
cat demos/jsoncols/myblob.json | bin/jsoncols -nl .name .email .age > temp.txt
547547
assert_exists "test_jsoncols (pipeline)" temp.txt
548548
R=$(cmp demos/jsoncols/result3.txt temp.txt)
549549
assert_empty "test_jsoncols (result3)" "$R"

0 commit comments

Comments
 (0)