-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
103 lines (84 loc) · 2.35 KB
/
main.go
File metadata and controls
103 lines (84 loc) · 2.35 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Package main is the entry point for the izrss application
package main
import (
"fmt"
"log"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/urfave/cli/v2"
"github.com/isabelroses/izrss/internal/config"
"github.com/isabelroses/izrss/internal/rss"
"github.com/isabelroses/izrss/internal/storage"
"github.com/isabelroses/izrss/internal/ui"
)
var version = "unstable"
func main() {
cli.AppHelpTemplate = fmt.Sprintf(`%s
CUSTOMIZATION:
The main bulk of customization is done via the "~/.config/izrss/config.toml" file. You can find an example file on the github page.
The rest of the config is done via using the environment variables "GLAMOUR_STYLE".
For a good example see: <https://github.com/catppuccin/glamour>`,
cli.AppHelpTemplate,
)
app := &cli.App{
Name: "izrss",
Version: version,
Authors: []*cli.Author{{
Name: "Isabel Roses",
Email: "isabel@isabelroses.com",
}},
Usage: "An RSS feed reader for the terminal.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Value: "",
Usage: "the path to your config file",
},
&cli.BoolFlag{
Name: "count-unread",
Usage: "count the number of unread posts",
},
},
Action: run,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
// Load configuration
cfg, err := config.Load(c.String("config"))
if err != nil {
return fmt.Errorf("loading config: %w", err)
}
if len(cfg.Urls) == 0 {
fmt.Println("No urls were found in config file, please add some and try again")
fmt.Println("You can find an example config file on the github page")
os.Exit(1)
}
// Initialize database
db, err := storage.NewDefault()
if err != nil {
return fmt.Errorf("initializing database: %w", err)
}
defer func() { _ = db.Close() }()
// Create fetcher and load feeds
fetcher := rss.NewFetcher(db, cfg.DateFormat)
feeds := fetcher.GetAllContent(cfg.Urls, fetcher.CheckCache())
if err := feeds.ReadTracking(db); err != nil {
return fmt.Errorf("reading tracking data: %w", err)
}
// Handle count-unread flag
if c.Bool("count-unread") {
fmt.Print(feeds.GetTotalUnreads())
return nil
}
// Run the TUI
m := ui.NewModel(cfg, db, fetcher)
m.SetFeeds(feeds)
p := tea.NewProgram(m, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
return fmt.Errorf("running TUI: %w", err)
}
return nil
}