|
1 // Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
|
2 // |
|
3 // Licensed under the MIT license. |
|
4 // Please see the LICENSE file is this directory. |
|
5 |
|
6 package cmd |
|
7 |
|
8 import ( |
|
9 "github.com/spf13/cobra" |
|
10 ) |
|
11 |
|
12 var timelineOpts struct { |
|
13 local bool |
|
14 } |
|
15 |
|
16 // timelineCmd represents the timelines command |
|
17 var timelineCmd = &cobra.Command{ |
|
18 Use: "timeline [home|public|:HASHTAG] [--local]", |
|
19 Aliases: []string{"tl"}, |
|
20 Short: "Fetch a timeline", |
|
21 Long: ` |
|
22 The timeline command fetches a timeline (home, local or federated). |
|
23 It can also get a hashtag-based timeline if the keyword or prefixed with |
|
24 ':' or '#'.`, |
|
25 Example: ` madonctl timeline |
|
26 madonctl timeline public --local |
|
27 madonctl timeline :mastodon`, |
|
28 RunE: timelineRunE, |
|
29 ValidArgs: []string{"home", "public"}, |
|
30 } |
|
31 |
|
32 func init() { |
|
33 RootCmd.AddCommand(timelineCmd) |
|
34 |
|
35 timelineCmd.Flags().BoolVar(&timelineOpts.local, "local", false, "Posts from the local instance") |
|
36 } |
|
37 |
|
38 func timelineRunE(cmd *cobra.Command, args []string) error { |
|
39 opt := timelineOpts |
|
40 |
|
41 tl := "home" |
|
42 if len(args) > 0 { |
|
43 tl = args[0] |
|
44 } |
|
45 |
|
46 // The home timeline is the only one requiring to be logged in |
|
47 if err := madonInit(tl == "home"); err != nil { |
|
48 return err |
|
49 } |
|
50 |
|
51 sl, err := gClient.GetTimelines(tl, opt.local) |
|
52 if err != nil { |
|
53 errPrint("Error: %s", err.Error()) |
|
54 return nil |
|
55 } |
|
56 |
|
57 p, err := getPrinter() |
|
58 if err != nil { |
|
59 return err |
|
60 } |
|
61 return p.PrintObj(sl, nil, "") |
|
62 } |