package cmd import ( "fmt" "log" "github.com/Jaculabilis/intake/core" "github.com/spf13/cobra" ) var feedCmd = &cobra.Command{ Use: "feed", Short: "Display the item feed", Long: fmt.Sprintf(`Display the intake item feed in various formats. The default format is "headlines". %s`, makeFormatHelpText()), Run: func(cmd *cobra.Command, args []string) { feed() }, } var feedFormat string var feedSource string var feedChannel string var feedShowInactive bool func init() { rootCmd.AddCommand(feedCmd) feedCmd.Flags().StringVarP(&feedFormat, "format", "f", "headlines", "Feed format") feedCmd.Flags().StringVarP(&feedSource, "source", "s", "", "Limit to items from source") feedCmd.Flags().StringVarP(&feedChannel, "channel", "c", "", "Limit to items from channel") feedCmd.MarkFlagsMutuallyExclusive("source", "channel") feedCmd.Flags().BoolVar(&feedShowInactive, "all", false, "Show inactive items") } func feed() { formatter := formatAs(feedFormat) db := openAndMigrateDb() var items []core.Item var err error if feedSource != "" { if feedShowInactive { items, err = core.GetAllItemsForSource(db, feedSource) } else { items, err = core.GetActiveItemsForSource(db, feedSource) } if err != nil { log.Fatalf("error: failed to fetch items from %s:, %v", feedSource, err) } } else if feedChannel != "" { log.Fatal("error: unimplemented") } else { if feedShowInactive { items, err = core.GetAllItems(db) } else { items, err = core.GetAllActiveItems(db) } if err != nil { log.Fatalf("error: failed to fetch items: %v", err) } } for _, item := range items { fmt.Println(formatter(item)) } }