-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
59 lines (47 loc) · 874 Bytes
/
main.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
package main
import (
"log"
"os"
"strconv"
cli "github.com/urfave/cli/v2"
"gorm.io/gorm"
)
func main() {
InitializeDb()
app := &cli.App{
Commands: []*cli.Command{
{
Name: "scrape",
Usage: "scrapes everything",
Action: ScrapeCommand,
},
{
Name: "generate",
Usage: "generates the site",
Action: Generate,
},
{
Name: "delete",
Usage: "deletes post by id",
Action: func(c *cli.Context) error {
sid := c.Args().Get(0)
if sid == "" {
log.Fatal("Can't delete empty id")
}
id, _ := strconv.ParseUint(sid, 10, 64)
post := Post{Model: gorm.Model{ID: uint(id)}}
err := Db.Find(&post).Error
if err != nil {
return err
}
err = Db.Delete(&post).Error
return err
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}