-
Notifications
You must be signed in to change notification settings - Fork 0
/
new.go
75 lines (59 loc) · 1.3 KB
/
new.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"log"
)
// Implemenets the Runner interface
type Create struct {
fs *flag.FlagSet
}
func NewCreate() *Create {
s := Create{
fs: flag.NewFlagSet("new", flag.ExitOnError),
}
return &s
}
func (s *Create) Parse(args []string) error {
// // TODO Improve
// filename := args[0]
// if path.Ext(filename) != ".md" {
// log.Fatalln("file type has to be .md")
// }
// data, err := os.ReadFile(filename)
// if err != nil {
// log.Fatal(err)
// }
// s.content = string(data)
return s.fs.Parse(args)
}
func (s *Create) Name() string {
return s.fs.Name()
}
// 1. Check that title and content is non-empty
// 2. Create the nostr event from the commandline arguments
// 3. Publish the event to the config relays
func (s *Create) Run(container *Container) error {
// // TODO move this to note opts
// if s.title == "" {
// return ErrNoTitle
// }
// if s.content == "" {
// return ErrNoContent
// }
// Get the current notebook instance
nb, err := container.CurrentNotebook()
if err != nil {
return err
}
if nb == nil {
log.Fatalln("no notebook specified")
}
// Add note to this notebook and publish to nostr relays
note, err := nb.Add()
if err != nil {
return err
}
fmt.Printf("[*] note created at: %s\n", note.Path)
return nil
}