-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.go
64 lines (48 loc) · 1.08 KB
/
push.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
package main
import (
"flag"
"fmt"
"path"
)
// > nz push /tmp/zk/202404041455.md
type Push struct {
fs *flag.FlagSet
filename string
title string
hashtags []string
}
func NewPush() *Push {
s := Push{
fs: flag.NewFlagSet("push", flag.ExitOnError),
}
s.fs.StringVar(&s.filename, "content", "", "the filename to be committed")
s.fs.StringVar(&s.title, "title", "", "the filename to be committed")
s.fs.Func("tag", "tag article", func(v string) error {
s.hashtags = append(s.hashtags, v)
return nil
})
return &s
}
func (s *Push) Parse(args []string) error {
return s.fs.Parse(args)
}
func (s *Push) Name() string {
return s.fs.Name()
}
// 1. Assume the filename is the article identifier
func (s *Push) Run(container *Container) error {
// Get the current notebook instance
nb, err := container.CurrentNotebook()
if err != nil {
return err
}
// TODO check different filetyopes
if path.Ext(s.filename) != ".md" {
return fmt.Errorf("file type has to be .md")
}
err = nb.Publish(s.filename, s.title, s.hashtags)
if err != nil {
return err
}
return nil
}