diff --git a/cmd/add.go b/cmd/add.go index 6f231de..7e5add2 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -30,12 +30,19 @@ var addCmd = &cobra.Command{ Short: "Adds a new feed to the application.", Long: `Validates and stores a feed in the application's database. Depending on the feed type, articles, videos, or updates are fetched right away. +The number of articles that are imported initially can be set with the --last flag. If it is not provided the last 10 items are imported. + Supported types currently are: - RSS feeds - Atom feeds `, + Example: `freed add "..." +freed add "..." --last 50 <- Imports the last 50 items in the feed`, Run: func(cmd *cobra.Command, args []string) { - feedName, articlesCount, err := internal.AddFeed(args[0]) + addRecentCount := 10 + addRecentCount, _ = cmd.Flags().GetInt("last") + + feedName, articlesCount, err := internal.AddFeed(args[0], addRecentCount) if err != nil { pterm.Error.Printf("Error adding feed: %v\n", err) diff --git a/internal/feed.go b/internal/feed.go index 9d14f8b..1bd1f03 100644 --- a/internal/feed.go +++ b/internal/feed.go @@ -4,12 +4,10 @@ import ( "fmt" "freed/internal/database" "net/url" - "strconv" "sync" "time" "github.com/mmcdole/gofeed" - "github.com/pterm/pterm" ) type Feed struct { @@ -21,7 +19,7 @@ type Feed struct { ArticleCount int } -func AddFeed(feedUrl string) (string, int, error) { +func AddFeed(feedUrl string, addRecentCount int) (string, int, error) { if _, err := url.ParseRequestURI(feedUrl); err != nil { return "", 0, fmt.Errorf("The given URL does not seem to be valid: %s", err) } @@ -42,11 +40,10 @@ func AddFeed(feedUrl string) (string, int, error) { return "", 0, err } - // TODO: Make the amount of articles configurable - articles := make([]database.ArticleEntity, 0, 10) + articles := make([]database.ArticleEntity, 0, addRecentCount) for i, v := range feed.Items { - if i > 10 { + if i > addRecentCount { continue }