Skip to content

Commit df680d3

Browse files
committed
Do not output notes as JSON as default behaviour
Needing to read the notebook as JSON is not a feature that has been used often so it shouldn't be the default behaviour. Now that 'zb' will not try to assume the notebook directory if it doesn't have it configured it makes sense to output help content by default and move JSON output under its own subcommand.
1 parent 24b7279 commit df680d3

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

cmd/json.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/msp301/zb/graph"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var jsonCmd = &cobra.Command{
12+
Use: "json",
13+
Short: "Output notes as JSON",
14+
Run: func(cmd *cobra.Command, args []string) {
15+
book().Notes.Walk(func(vertex graph.Vertex, depth int) bool {
16+
jsonStr, err := json.Marshal(vertex)
17+
if err != nil {
18+
panic(err)
19+
}
20+
fmt.Println(string(jsonStr))
21+
return true
22+
}, -1)
23+
},
24+
}
25+
26+
func init() {
27+
rootCmd.AddCommand(jsonCmd)
28+
}

cmd/root.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package cmd
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"log"
76
"os"
87
"path"
98

109
"github.com/msp301/zb/config"
1110
"github.com/msp301/zb/editor"
12-
"github.com/msp301/zb/graph"
1311
"github.com/spf13/cobra"
1412
"github.com/spf13/viper"
1513
)
@@ -21,14 +19,7 @@ var rootCmd = &cobra.Command{
2119
Use: "zb",
2220
Short: "A Zettelkasten notebook utility",
2321
Run: func(cmd *cobra.Command, args []string) {
24-
book().Notes.Walk(func(vertex graph.Vertex, depth int) bool {
25-
jsonStr, err := json.Marshal(vertex)
26-
if err != nil {
27-
panic(err)
28-
}
29-
fmt.Println(string(jsonStr))
30-
return true
31-
}, -1)
22+
cmd.Help()
3223
},
3324
}
3425

0 commit comments

Comments
 (0)