-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters