Skip to content

Commit

Permalink
Do not output notes as JSON as default behaviour
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msp301 committed May 19, 2024
1 parent 24b7279 commit df680d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
28 changes: 28 additions & 0 deletions cmd/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/msp301/zb/graph"
"github.com/spf13/cobra"
)

var jsonCmd = &cobra.Command{
Use: "json",
Short: "Output notes as JSON",
Run: func(cmd *cobra.Command, args []string) {
book().Notes.Walk(func(vertex graph.Vertex, depth int) bool {
jsonStr, err := json.Marshal(vertex)
if err != nil {
panic(err)
}
fmt.Println(string(jsonStr))
return true
}, -1)
},
}

func init() {
rootCmd.AddCommand(jsonCmd)
}
11 changes: 1 addition & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package cmd

import (
"encoding/json"
"fmt"
"log"
"os"
"path"

"github.com/msp301/zb/config"
"github.com/msp301/zb/editor"
"github.com/msp301/zb/graph"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -21,14 +19,7 @@ var rootCmd = &cobra.Command{
Use: "zb",
Short: "A Zettelkasten notebook utility",
Run: func(cmd *cobra.Command, args []string) {
book().Notes.Walk(func(vertex graph.Vertex, depth int) bool {
jsonStr, err := json.Marshal(vertex)
if err != nil {
panic(err)
}
fmt.Println(string(jsonStr))
return true
}, -1)
cmd.Help()
},
}

Expand Down

0 comments on commit df680d3

Please sign in to comment.