From 1c3cfd106c71882d0251a8bf694c6333bdd47a8d Mon Sep 17 00:00:00 2001 From: CronyAkatsuki Date: Sat, 11 Nov 2023 20:31:35 +0100 Subject: [PATCH] Add ability to list feeds of a category. By providing a category id after the feeds command, list the feeds in that category. --- main.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 5d71e49..c56f9e9 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( // Help message const HELP = `examples: mfeed create {category_id} {feed_url} + mfeed feeds {category_id} usage: mfeed [-h] {feeds,categories,create} ... feeds list all the feeds you have @@ -92,15 +93,30 @@ func main() { return } -// Print out all your feeds and their id's +// Print out all your feeds and their id's, or feeds in a category if provided func feeds(client *miniflux.Client) { - feeds, err := client.Feeds() - if err != nil { - fmt.Println(err) + if len(os.Args) < 3 { + feeds, err := client.Feeds() + if err != nil { + fmt.Println(err) + return + } + for _, feed := range feeds { + fmt.Printf("%d\t%s\n", feed.ID, feed.Title) + } return - } - for _, feed := range feeds { - fmt.Printf("%d\t%s\n", feed.ID, feed.Title) + } else if len(os.Args) > 3 { + fmt.Println("Too many arguments provided!") + return + } else { + category, err := strconv.Atoi(os.Args[2]) + if err != nil { + panic(err) + } + feeds, err := client.CategoryFeeds(int64(category)) + for _, feed := range feeds { + fmt.Printf("%d\t%s\n", feed.ID, feed.Title) + } } }