Author:
Hash:
Timestamp:
+34 -14 +/-1 browse
Kevin Schoon [me@kevinschoon.com]
2de75d0ff7ced0b251647833476bd0c6d101d2bb
Fri, 03 Oct 2025 11:06:42 +0000 (1 month ago)
| 1 | diff --git a/pkg/cmd/app.go b/pkg/cmd/app.go |
| 2 | index e037ad5..268e296 100644 |
| 3 | --- a/pkg/cmd/app.go |
| 4 | +++ b/pkg/cmd/app.go |
| 5 | @@ -26,11 +26,19 @@ func today() string { |
| 6 | return fmt.Sprintf("/daily/%d-%d-%d", year, day, int(month)) |
| 7 | } |
| 8 | |
| 9 | - func printNote(note *hierarchy.Note, all bool) { |
| 10 | - fmt.Println(note.Content) |
| 11 | - if all { |
| 12 | - for i := 0; i < len(note.Descendants); i++ { |
| 13 | - printNote(note.Descendants[i], all) |
| 14 | + func printNote(note *hierarchy.Note, all bool, as_json bool) { |
| 15 | + if as_json { |
| 16 | + note_bytes, err := json.Marshal(note) |
| 17 | + if err != nil { |
| 18 | + panic(err) |
| 19 | + } |
| 20 | + fmt.Println(string(note_bytes)) |
| 21 | + } else { |
| 22 | + fmt.Println(note.Content) |
| 23 | + if all { |
| 24 | + for i := 0; i < len(note.Descendants); i++ { |
| 25 | + printNote(note.Descendants[i], all, false) |
| 26 | + } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | @@ -198,9 +206,8 @@ data structure. It uses SQLite to store note content and metadata. |
| 31 | ArgsUsage: "note path", |
| 32 | Flags: []cli.Flag{ |
| 33 | &cli.StringFlag{ |
| 34 | - Name: "encoding", |
| 35 | - Aliases: []string{"e"}, |
| 36 | - Usage: "output format", |
| 37 | + Name: "json", |
| 38 | + Usage: "output note in json format", |
| 39 | }, |
| 40 | &cli.BoolFlag{ |
| 41 | Name: "all", |
| 42 | @@ -211,13 +218,26 @@ data structure. It uses SQLite to store note content and metadata. |
| 43 | Action: func(ctx *cli.Context) error { |
| 44 | path := ctx.Args().First() |
| 45 | if path == "" { |
| 46 | - path = today() |
| 47 | - } |
| 48 | - note, err := hierarchy.Find(*cfg, path) |
| 49 | - if err != nil { |
| 50 | - return err |
| 51 | + notes, err := hierarchy.Load(*cfg) |
| 52 | + if err != nil { |
| 53 | + return err |
| 54 | + } |
| 55 | + printNote(&hierarchy.Note{ |
| 56 | + ID: 0, |
| 57 | + CreatedAt: time.Time{}, |
| 58 | + ModifiedAt: time.Time{}, |
| 59 | + Name: "", |
| 60 | + Content: "", |
| 61 | + Parent: nil, |
| 62 | + Descendants: notes, |
| 63 | + }, true, ctx.Bool("json")) |
| 64 | + } else { |
| 65 | + note, err := hierarchy.Find(*cfg, path) |
| 66 | + if err != nil { |
| 67 | + return err |
| 68 | + } |
| 69 | + printNote(note, ctx.Bool("all"), ctx.Bool("json")) |
| 70 | } |
| 71 | - printNote(note, ctx.Bool("all")) |
| 72 | return nil |
| 73 | }, |
| 74 | }, |