/* Copyright © 2024 NAME HERE */ package cmd import ( "github.com/spf13/cobra" "github.com/spf13/viper" "git.alecodes.page/alecodes/miniflux-archiver/internal/app" "git.alecodes.page/alecodes/miniflux-archiver/internal/logger" "git.alecodes.page/alecodes/miniflux-archiver/internal/miniflux" "git.alecodes.page/alecodes/miniflux-archiver/internal/service" ) var Services = []string{ string(service.ServiceLinkding), } var ( service_host string service_user string service_token string service_max_requests uint8 archive_seen bool archive_starred bool archive_method string ) // archiveCmd represents the archive command var archiveCmd = &cobra.Command{ Use: "archive", Short: "Archive the rss entries to an external service.", Aliases: []string{"run"}, Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), ValidArgs: Services, Run: func(cmd *cobra.Command, args []string) { serviceOption := service.ServiceOption(args[0]) serviceConfig := service.ServiceConfig{ Service: serviceOption, Host: viper.GetString("service_host"), User: viper.GetString("service_user"), Token: viper.GetString("service_token"), Method: service.ServiceArchiveMethod(archive_method), MaxRequests: service_max_requests, } minifluxConfig := miniflux.MinifluxConfig{ Host: viper.GetString("miniflux_host"), Token: viper.GetString("miniflux_token"), FeedId: viper.GetInt64("miniflux_feed_id"), FeedFilter: &miniflux.Filter{}, } if archive_seen { logger.Info("Archiving Feed %v entries", minifluxConfig.FeedId) app.Archive(minifluxConfig, serviceConfig) } if archive_starred { logger.Info("Archiving All starred entries") minifluxConfig.FeedFilter.Starred = "true" minifluxConfig.FeedId = -1 app.Archive(minifluxConfig, serviceConfig) } }, } func init() { rootCmd.AddCommand(archiveCmd) archiveCmd.Flags(). BoolVarP(&archive_seen, "archive-seen", "s", true, "If the seen entries should be archived") archiveCmd.Flags(). BoolVarP(&archive_starred, "archive-starred", "S", false, "If the starred entries should be archived") archiveCmd.Flags(). StringVarP(&archive_method, "archive-method", "m", "seen", "What action to apply to the entries, possible values are: seen, archive, both") archiveCmd.Flags().StringVar(&service_host, "service-host", "", "127.0.0.1") archiveCmd.Flags().StringVar(&service_user, "service-user", "", "john.doe@mail.cl") archiveCmd.Flags().StringVar(&service_token, "service-token", "", "XXX-XXX-XXX") archiveCmd.Flags(). Uint8Var(&service_max_requests, "service_max_requests", 5, "Maximum alowed of concurrent requests") viper.BindPFlag("service_host", archiveCmd.Flags().Lookup("service-host")) viper.BindPFlag("service_host", archiveCmd.Flags().Lookup("service-host")) viper.BindPFlag("service_token", archiveCmd.Flags().Lookup("service-token")) viper.BindPFlag("service_max_requests", archiveCmd.Flags().Lookup("service-max-requests")) }