all repos

smutok @ e1ab4d0a127d05682d6c3ad3e48b6acd5b6ecbdf

yet another tui rss reader (not abandoned, just paused development)

smutok/main.go(view raw)

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
package main

import (
	"context"
	_ "embed"
	"fmt"
	"log/slog"
	"os"
	"strings"

	tea "github.com/charmbracelet/bubbletea"
	"github.com/urfave/cli/v3"
	"olexsmir.xyz/smutok/internal/config"
	"olexsmir.xyz/smutok/internal/tui"
)

//go:embed version
var _version string

var version = strings.Trim(_version, "\n")

func main() {
	cmd := &cli.Command{
		Name:                  "smutok",
		Version:               version,
		Usage:                 "An RSS feed reader.",
		EnableShellCompletion: true,
		Action:                runTui,
		Commands: []*cli.Command{
			initConfigCmd,
			syncFeedsCmd,
		},
	}
	if err := cmd.Run(context.Background(), os.Args); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}
}

func runTui(ctx context.Context, c *cli.Command) error {
	app, err := bootstrap(ctx, true)
	if err != nil {
		return err
	}
	go func() { app.freshrssWorker.Run(ctx) }()

	model := tui.NewModel(ctx, app.freshrssSyncer, app.store)
	_, err = tea.NewProgram(model).Run()
	return err
}

// sync

var syncFeedsCmd = &cli.Command{
	Name:    "sync",
	Usage:   "Sync RSS feeds without opening the tui.",
	Aliases: []string{"s"},
	Action:  syncFeeds,
}

func syncFeeds(ctx context.Context, c *cli.Command) error {
	app, err := bootstrap(ctx, false)
	if err != nil {
		return err
	}
	return app.freshrssSyncer.Sync(ctx)
}

// init

var initConfigCmd = &cli.Command{
	Name:   "init",
	Usage:  "Initialize smutok's config",
	Action: initConfig,
}

func initConfig(ctx context.Context, c *cli.Command) error {
	if err := config.Init(); err != nil {
		return fmt.Errorf("failed to init config: %w", err)
	}
	slog.Info(
		"Config was initialized, enter your credentials",
		"file", config.MustGetConfigFilePath(),
	)
	return nil
}