cmd/timelines.go
changeset 198 e9c2947a84a6
parent 185 564d92b54b00
child 200 488f5fc5be98
equal deleted inserted replaced
197:0b0fd2f02296 198:e9c2947a84a6
     5 
     5 
     6 package cmd
     6 package cmd
     7 
     7 
     8 import (
     8 import (
     9 	"os"
     9 	"os"
       
    10 	"strings"
    10 
    11 
    11 	"github.com/spf13/cobra"
    12 	"github.com/spf13/cobra"
    12 
    13 
    13 	"github.com/McKael/madon"
    14 	"github.com/McKael/madon"
    14 )
    15 )
    19 	sinceID, maxID int64
    20 	sinceID, maxID int64
    20 }
    21 }
    21 
    22 
    22 // timelineCmd represents the timelines command
    23 // timelineCmd represents the timelines command
    23 var timelineCmd = &cobra.Command{
    24 var timelineCmd = &cobra.Command{
    24 	Use:     "timeline [home|public|:HASHTAG] [--local]",
    25 	Use:     "timeline [home|public|:HASHTAG|!list_id] [--local]",
    25 	Aliases: []string{"tl"},
    26 	Aliases: []string{"tl"},
    26 	Short:   "Fetch a timeline",
    27 	Short:   "Fetch a timeline",
    27 	Long: `
    28 	Long: `
    28 The timeline command fetches a timeline (home, local or federated).
    29 The timeline command fetches a timeline (home, local or federated).
    29 It can also get a hashtag-based timeline if the keyword or prefixed with
    30 It can also get a hashtag-based timeline if the keyword or prefixed with
    30 ':' or '#'.`,
    31 ':' or '#', or a list-based timeline (use !ID with the list ID).`,
    31 	Example: `  madonctl timeline
    32 	Example: `  madonctl timeline
    32   madonctl timeline public --local
    33   madonctl timeline public --local
       
    34   madonctl timeline '!42'
    33   madonctl timeline :mastodon`,
    35   madonctl timeline :mastodon`,
    34 	RunE:      timelineRunE,
    36 	RunE:      timelineRunE,
    35 	ValidArgs: []string{"home", "public"},
    37 	ValidArgs: []string{"home", "public"},
    36 }
    38 }
    37 
    39 
    66 	tl := "home"
    68 	tl := "home"
    67 	if len(args) > 0 {
    69 	if len(args) > 0 {
    68 		tl = args[0]
    70 		tl = args[0]
    69 	}
    71 	}
    70 
    72 
    71 	// The home timeline is the only one requiring to be logged in
    73 	// Home timeline and list-based timeline require to be logged in
    72 	if err := madonInit(tl == "home"); err != nil {
    74 	if err := madonInit(tl == "home" || strings.HasPrefix(tl, "!")); err != nil {
    73 		return err
    75 		return err
    74 	}
    76 	}
    75 
    77 
    76 	sl, err := gClient.GetTimelines(tl, opt.local, limOpts)
    78 	sl, err := gClient.GetTimelines(tl, opt.local, limOpts)
    77 	if err != nil {
    79 	if err != nil {