-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_feeds.go
52 lines (46 loc) · 1.28 KB
/
list_feeds.go
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
package cli
import (
"fmt"
"github.com/mradile/rssfeeder/pkg/client/configuration"
"github.com/mradile/rssfeeder/pkg/rest"
"github.com/pkg/errors"
"github.com/urfave/cli"
"net/http"
)
func (c *client) ListFeeds() cli.Command {
cmd := cli.Command{
Name: "list",
ShortName: "l",
Usage: "list all feeds with their URIs",
UsageText: "list",
Action: func(c *cli.Context) error {
setLogLevel(c)
cfg, err := configuration.Load(c.GlobalString("cfg"))
if err != nil {
return cli.NewExitError(errors.Wrap(err, "could not list feeds"), 1)
}
Client.cfg = cfg
req, err := Client.makeHTTPRequest("GET", "/api/v1/feed", nil)
if err != nil {
return cli.NewExitError(errors.Wrap(err, "could not list feeds"), 1)
}
err = Client.setAuthHeader(req)
if err != nil {
return cli.NewExitError(errors.Wrap(err, "could not list feeds"), 1)
}
var list rest.FeedListResponse
if err := Client.getResponse(req, &list, http.StatusOK); err != nil {
return cli.NewExitError(errors.Wrap(err, "could not list feeds"), 1)
}
fmt.Println("Feeds:")
for _, feed := range list.Feeds {
fmt.Printf("Feed: %s [ID: %d]\n", feed.Name, feed.ID)
for _, uri := range feed.URIs {
fmt.Printf("\t%s\n", uri)
}
}
return nil
},
}
return cmd
}