Skip to content

Commit f2a387a

Browse files
committed
Quick Save
1 parent ef657a9 commit f2a387a

File tree

19 files changed

+239
-18
lines changed

19 files changed

+239
-18
lines changed

cmds/findfile/findfile.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ Search the current directory and subdirectories for Markdown files with extensio
6767
pathSep string
6868
)
6969

70-
func display(out io.Writer, docroot, p string, m time.Time) {
70+
func display(w io.Writer, docroot, p string, m time.Time) {
7171
var s string
7272
if outputFullPath == true {
7373
s, _ = filepath.Abs(p)
7474
} else {
7575
s, _ = filepath.Rel(docroot, p)
7676
}
7777
if showModificationTime == true {
78-
fmt.Fprintf(out, "%s %s\n", m.Format("2006-01-02 15:04:05 -0700"), s)
78+
fmt.Fprintf(w, "%s %s\n", m.Format("2006-01-02 15:04:05 -0700"), s)
7979
return
8080
}
81-
fmt.Fprintf(out, "%s\n", s)
81+
fmt.Fprintf(w, "%s\n", s)
8282
}
8383

8484
func walkPath(out io.Writer, docroot string, target string) error {
@@ -215,7 +215,7 @@ func main() {
215215

216216
// For each directory to search walk the path
217217
for _, dir := range args {
218-
err := walkPath(app.Out, dir, target)
218+
err = walkPath(app.Out, dir, target)
219219
cli.ExitOnError(app.Eout, err, quiet)
220220
}
221221
fmt.Fprintf(app.Out, "%s", eol)

demos/finddir/documents/t4.txt

Whitespace-only changes.

demos/findfile/documents/t5.txt

Whitespace-only changes.

demos/jsonjoin/demo.bash

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
cat <<EOF > person.json
4+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42 }
5+
EOF
6+
echo -n "This is person.json: "
7+
cat person.json
8+
echo ''
9+
10+
cat <<EOF > profile.json
11+
{ "name": "Doe, Jane", "bio": "World renowned geophysist.", "email": "[email protected]" }
12+
EOF
13+
echo -n "This is profile.json: "
14+
cat profile.json
15+
echo ''
16+
17+
echo ' running: jsonjoin -create person.json profile.json'
18+
jsonjoin -create person.json profile.json > result1.json
19+
echo -n 'expected: '
20+
cat expected1.json
21+
echo -n ' got: '
22+
cat result1.json
23+
echo ''
24+
25+
26+
echo ' running: cat person.json | jsonjoin profile.json'
27+
cat person.json | jsonjoin -i - profile.json > result2.json
28+
echo -n 'expected: '
29+
cat expected2.json
30+
echo -n ' got: '
31+
cat result2.json
32+
echo ''
33+
34+
echo ' running: jsonjoin -i person.json profile.json'
35+
jsonjoin -i person.json profile.json > result3.json
36+
echo -n 'expected: '
37+
cat expected3.json
38+
echo -n ' got: '
39+
cat result3.json
40+
echo ''
41+
42+
echo ' running: jsonjoin -create -update person.json profile.json'
43+
jsonjoin -create -update person.json profile.json > result4.json
44+
echo -n 'expected: '
45+
cat expected4.json
46+
echo -n ' got: '
47+
cat result4.json
48+
echo ''
49+
50+
echo ' running: jsonjoin -create -update profile.json person.json'
51+
jsonjoin -create -update profile.json person.json > result5.json
52+
echo -n 'expected: '
53+
cat expected5.json
54+
echo -n ' got: '
55+
cat result5.json
56+
echo ''
57+
58+
echo ' running: jsonjoin -create -overwrite person.json profile.json'
59+
jsonjoin -create -overwrite person.json profile.json > result6.json
60+
echo -n 'expected: '
61+
cat expected6.json
62+
echo -n ' got: '
63+
cat result6.json
64+
echo ''

demos/jsonjoin/expected1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "person": { "name": "Doe, Jane", "email":"[email protected]", "age": 42}, "profile": { "name": "Doe, Jane", "bio": "World renowned geophysist.", "email": "[email protected]" } }

demos/jsonjoin/expected3.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42, "profile": { "name": "Doe, Jane", "bio": "World renowned geophysist.", "email": "[email protected]" } }

demos/jsonjoin/expected4.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42, "bio": "World renowned geophysist." }

demos/jsonjoin/expected5.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "name": "Doe, Jane", "age": 42, "bio": "World renowned geophysist.", "email": "[email protected]" }

demos/jsonjoin/expected6.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42, "bio": "World renowned geophysist." }

demos/jsonjoin/index.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
# demo jsonjoin
3+
4+
Consider two JSON objects one in person.json and another
5+
in profile.json.
6+
7+
person.json contains
8+
9+
```shell
10+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42 }
11+
```
12+
13+
profile.json contains
14+
15+
```json
16+
{ "name": "Doe, Jane", "bio": "World renowned geophysist.",
17+
"email": "[email protected]" }
18+
```
19+
20+
A simple join of person.json with profile.json (note the
21+
-create option)
22+
23+
```shell
24+
jsonjoin -create person.json profile.json
25+
```
26+
27+
would yield and object like
28+
29+
```json
30+
{
31+
"person": { "name": "Doe, Jane", "email":"[email protected]",
32+
"age": 42},
33+
"profile": { "name": "Doe, Jane", "bio": "World renowned geophysist.",
34+
"email": "[email protected]" }
35+
}
36+
```
37+
38+
Likewise if you want to treat person.json as the root object and add
39+
profile.json as a branch try
40+
41+
```shell
42+
cat person.json | jsonjoin profile.json
43+
```
44+
45+
or
46+
47+
```shell
48+
jsonjoin -i person.json profile.json
49+
```
50+
51+
this yields an object like
52+
53+
```json
54+
{
55+
"name": "Doe, Jane", "email":"[email protected]", "age": 42,
56+
"profile": { "name": "Doe, Jane", "bio": "World renowned geophysist.",
57+
"email": "[email protected]" }
58+
}
59+
```
60+
61+
You can modify this behavor with -update or -overwrite. Both options are
62+
order dependant (i.e. not associative, A update B does
63+
not necessarily equal B update A).
64+
65+
+ -update will add unique key/values from the second object to the first object
66+
+ -overwrite replace key/values in first object one with second objects'
67+
68+
Running
69+
70+
```shell
71+
jsonjoin -create -update person.json profile.json
72+
```
73+
74+
would yield
75+
76+
```json
77+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42,
78+
"bio": "World renowned geophysist." }
79+
```
80+
81+
Running
82+
83+
```shell
84+
jsonjoin -create -update profile.json person.json
85+
```
86+
87+
would yield
88+
89+
```json
90+
{ "name": "Doe, Jane", "age": 42,
91+
"bio": "World renowned geophysist.",
92+
"email": "[email protected]" }
93+
```
94+
95+
Running
96+
97+
```shell
98+
jsonjoin -create -overwrite person.json profile.json
99+
```
100+
101+
would yield
102+
103+
```json
104+
{ "name": "Doe, Jane", "email":"[email protected]", "age": 42,
105+
"bio": "World renowned geophysist." }
106+
```
107+

0 commit comments

Comments
 (0)