-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotify_cmd.go
47 lines (41 loc) · 1.14 KB
/
notify_cmd.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
package main
import (
"context"
"flag"
"fmt"
"github.com/google/subcommands"
"io"
"os"
)
type notifyCmd struct {
}
func (*notifyCmd) Name() string { return "notify" }
func (*notifyCmd) Synopsis() string { return "add links to changes.md, index.md, and hashtag pages" }
func (*notifyCmd) Usage() string {
return `notify <page name> ...:
For each page, add entries to changes.md, index.md, and hashtag pages.
This is useful when writing pages offline and replicates the behaviour
triggered by the "Add link to the list of changes" checkbox, online.
`
}
func (cmd *notifyCmd) SetFlags(f *flag.FlagSet) {
}
func (cmd *notifyCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
return notifyCli(os.Stdout, f.Args())
}
func notifyCli(w io.Writer, args []string) subcommands.ExitStatus {
index.load()
for _, name := range args {
p, err := loadPage(name)
if err != nil {
fmt.Fprintf(w, "Loading %s: %s\n", name, err)
return subcommands.ExitFailure
}
err = p.notify()
if err != nil {
fmt.Fprintf(w, "%s: %s\n", name, err)
return subcommands.ExitFailure
}
}
return subcommands.ExitSuccess
}