-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
56 lines (41 loc) · 984 Bytes
/
init.go
File metadata and controls
56 lines (41 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"flag"
"fmt"
"log/slog"
"os"
)
// Creates a notebook structure that abstracts the local working directory.
type Init struct {
fs *flag.FlagSet
}
func NewInit() *Init {
s := Init{
fs: flag.NewFlagSet("init", flag.ExitOnError),
}
return &s
}
func (s *Init) Parse(args []string) error {
return s.fs.Parse(args)
}
func (s *Init) Name() string {
return s.fs.Name()
}
// 1. Creates a new Notebook
// 2. Inits all the author articles from nostr relays
// 3. Stores each event in the notebook as a note
func (s *Init) Run(container *Container) error {
dir, ok := os.LookupEnv("NOTEBOOK")
if !ok {
return fmt.Errorf("NOTEBOOK env var not set")
}
nb := NewNotebook(container.cfg, container.db, dir)
notes, err := nb.Init()
if err != nil {
return err
}
// Add the newly created notebook to the container
container.notebook = nb
slog.Info("notebook initiated with %d notes pulled from relays", "noteCount", len(notes))
return nil
}