Add ability to list feeds of a category.

By providing a category id after the feeds command, list the feeds in that category.
This commit is contained in:
CronyAkatsuki 2023-11-11 20:31:35 +01:00
parent a5a58dfd32
commit 1c3cfd106c

30
main.go
View File

@ -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)
}
}
}