[mirror] yet another tui rss reader
github.com/olexsmir/smutok
1package main
2
3import (
4 "context"
5 _ "embed"
6 "fmt"
7 "log/slog"
8 "os"
9 "strings"
10
11 tea "github.com/charmbracelet/bubbletea"
12 "github.com/urfave/cli/v3"
13 "olexsmir.xyz/smutok/internal/config"
14 "olexsmir.xyz/smutok/internal/tui"
15)
16
17//go:embed version
18var _version string
19
20var version = strings.Trim(_version, "\n")
21
22func main() {
23 cmd := &cli.Command{
24 Name: "smutok",
25 Version: version,
26 Usage: "An RSS feed reader.",
27 EnableShellCompletion: true,
28 Action: runTui,
29 Commands: []*cli.Command{
30 initConfigCmd,
31 syncFeedsCmd,
32 },
33 }
34 if err := cmd.Run(context.Background(), os.Args); err != nil {
35 fmt.Fprintf(os.Stderr, "%v\n", err)
36 os.Exit(1)
37 }
38}
39
40func runTui(ctx context.Context, c *cli.Command) error {
41 app, err := bootstrap(ctx, true)
42 if err != nil {
43 return err
44 }
45 go func() { app.freshrssWorker.Run(ctx) }()
46
47 model := tui.NewModel(ctx, app.freshrssSyncer, app.store)
48 _, err = tea.NewProgram(model).Run()
49 return err
50}
51
52// sync
53
54var syncFeedsCmd = &cli.Command{
55 Name: "sync",
56 Usage: "Sync RSS feeds without opening the tui.",
57 Aliases: []string{"s"},
58 Action: syncFeeds,
59}
60
61func syncFeeds(ctx context.Context, c *cli.Command) error {
62 app, err := bootstrap(ctx, false)
63 if err != nil {
64 return err
65 }
66 return app.freshrssSyncer.Sync(ctx)
67}
68
69// init
70
71var initConfigCmd = &cli.Command{
72 Name: "init",
73 Usage: "Initialize smutok's config",
74 Action: initConfig,
75}
76
77func initConfig(ctx context.Context, c *cli.Command) error {
78 if err := config.Init(); err != nil {
79 return fmt.Errorf("failed to init config: %w", err)
80 }
81 slog.Info(
82 "Config was initialized, enter your credentials",
83 "file", config.MustGetConfigFilePath(),
84 )
85 return nil
86}