cmd/timelines.go
changeset 22 5778b09bc6fe
parent 20 b0ccc09f07a2
child 44 6da40ca4534c
equal deleted inserted replaced
21:9e94836dc081 22:5778b09bc6fe
    10 
    10 
    11 	"github.com/McKael/madon"
    11 	"github.com/McKael/madon"
    12 )
    12 )
    13 
    13 
    14 var timelineOpts struct {
    14 var timelineOpts struct {
    15 	local bool
    15 	local                 bool
    16 	limit uint
    16 	limit, sinceID, maxID uint
    17 }
    17 }
    18 
    18 
    19 // timelineCmd represents the timelines command
    19 // timelineCmd represents the timelines command
    20 var timelineCmd = &cobra.Command{
    20 var timelineCmd = &cobra.Command{
    21 	Use:     "timeline [home|public|:HASHTAG] [--local]",
    21 	Use:     "timeline [home|public|:HASHTAG] [--local]",
    35 func init() {
    35 func init() {
    36 	RootCmd.AddCommand(timelineCmd)
    36 	RootCmd.AddCommand(timelineCmd)
    37 
    37 
    38 	timelineCmd.Flags().BoolVar(&timelineOpts.local, "local", false, "Posts from the local instance")
    38 	timelineCmd.Flags().BoolVar(&timelineOpts.local, "local", false, "Posts from the local instance")
    39 	timelineCmd.Flags().UintVarP(&timelineOpts.limit, "limit", "l", 0, "Limit number of results")
    39 	timelineCmd.Flags().UintVarP(&timelineOpts.limit, "limit", "l", 0, "Limit number of results")
       
    40 	timelineCmd.PersistentFlags().UintVar(&timelineOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
       
    41 	timelineCmd.PersistentFlags().UintVar(&timelineOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
    40 }
    42 }
    41 
    43 
    42 func timelineRunE(cmd *cobra.Command, args []string) error {
    44 func timelineRunE(cmd *cobra.Command, args []string) error {
    43 	opt := timelineOpts
    45 	opt := timelineOpts
    44 	var limOpts *madon.LimitParams
    46 	var limOpts *madon.LimitParams
    45 
    47 
       
    48 	if opt.limit > 0 || opt.sinceID > 0 || opt.maxID > 0 {
       
    49 		limOpts = new(madon.LimitParams)
       
    50 	}
       
    51 
    46 	if opt.limit > 0 {
    52 	if opt.limit > 0 {
    47 		limOpts = new(madon.LimitParams)
       
    48 		limOpts.Limit = int(opt.limit)
    53 		limOpts.Limit = int(opt.limit)
       
    54 	}
       
    55 	if opt.maxID > 0 {
       
    56 		limOpts.MaxID = int(opt.maxID)
       
    57 	}
       
    58 	if opt.sinceID > 0 {
       
    59 		limOpts.SinceID = int(opt.sinceID)
    49 	}
    60 	}
    50 
    61 
    51 	tl := "home"
    62 	tl := "home"
    52 	if len(args) > 0 {
    63 	if len(args) > 0 {
    53 		tl = args[0]
    64 		tl = args[0]