aboutsummaryrefslogtreecommitdiff
path: root/internal/cli
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <f@miniflux.net> 2023-09-27 21:15:32 -0700
committerGravatar Frédéric Guillot <f@miniflux.net> 2023-09-27 21:45:23 -0700
commitf98fc1e03a6d732611fc05a7f714e3f3a0292cfc (patch)
tree62745f05871fe2d2f35dfa87ab3b2e535c52e6fa /internal/cli
parent39d752ca85d0f590684af76f53eedbdc53f81801 (diff)
downloadv2-f98fc1e03a6d732611fc05a7f714e3f3a0292cfc.tar.gz
v2-f98fc1e03a6d732611fc05a7f714e3f3a0292cfc.tar.zst
v2-f98fc1e03a6d732611fc05a7f714e3f3a0292cfc.zip
Add command line argument to export user feeds
Diffstat (limited to 'internal/cli')
-rw-r--r--internal/cli/cli.go8
-rw-r--r--internal/cli/export_feeds.go30
2 files changed, 38 insertions, 0 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index f74ea5aa..a1ef7eef 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -32,6 +32,7 @@ const (
flagHealthCheckHelp = `Perform a health check on the given endpoint (the value "auto" try to guess the health check endpoint).`
flagRefreshFeedsHelp = "Refresh a batch of feeds and exit"
flagRunCleanupTasksHelp = "Run cleanup tasks (delete old sessions and archives old entries)"
+ flagExportUserFeedsHelp = "Export user feeds (provide the username as argument)"
)
// Parse parses command line arguments.
@@ -51,6 +52,7 @@ func Parse() {
flagHealthCheck string
flagRefreshFeeds bool
flagRunCleanupTasks bool
+ flagExportUserFeeds string
)
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
@@ -69,6 +71,7 @@ func Parse() {
flag.StringVar(&flagHealthCheck, "healthcheck", "", flagHealthCheckHelp)
flag.BoolVar(&flagRefreshFeeds, "refresh-feeds", false, flagRefreshFeedsHelp)
flag.BoolVar(&flagRunCleanupTasks, "run-cleanup-tasks", false, flagRunCleanupTasksHelp)
+ flag.StringVar(&flagExportUserFeeds, "export-user-feeds", "", flagExportUserFeedsHelp)
flag.Parse()
cfg := config.NewParser()
@@ -177,6 +180,11 @@ func Parse() {
return
}
+ if flagExportUserFeeds != "" {
+ exportUserFeeds(store, flagExportUserFeeds)
+ return
+ }
+
if flagFlushSessions {
flushSessions(store)
return
diff --git a/internal/cli/export_feeds.go b/internal/cli/export_feeds.go
new file mode 100644
index 00000000..0d0d5da5
--- /dev/null
+++ b/internal/cli/export_feeds.go
@@ -0,0 +1,30 @@
+// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+package cli // import "miniflux.app/v2/internal/cli"
+
+import (
+ "fmt"
+
+ "miniflux.app/v2/internal/reader/opml"
+ "miniflux.app/v2/internal/storage"
+)
+
+func exportUserFeeds(store *storage.Storage, username string) {
+ user, err := store.UserByUsername(username)
+ if err != nil {
+ printErrorAndExit(fmt.Errorf("unable to find user: %w", err))
+ }
+
+ if user == nil {
+ printErrorAndExit(fmt.Errorf("user %q not found", username))
+ }
+
+ opmlHandler := opml.NewHandler(store)
+ opmlExport, err := opmlHandler.Export(user.ID)
+ if err != nil {
+ printErrorAndExit(fmt.Errorf("unable to export feeds: %w", err))
+ }
+
+ fmt.Println(opmlExport)
+}