generated from alecodes/base-template
fead: expand archive options
add an option to select how to archive the entries add an option for what entries to archive change the concurrentcy limit to a semaphore instead of a ticker
This commit is contained in:
parent
1788241cd5
commit
b0506c3eab
9 changed files with 99 additions and 72 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"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"
|
||||
)
|
||||
|
|
@ -17,9 +18,14 @@ var Services = []string{
|
|||
}
|
||||
|
||||
var (
|
||||
service_host string
|
||||
service_user string
|
||||
service_token string
|
||||
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
|
||||
|
|
@ -33,30 +39,53 @@ var archiveCmd = &cobra.Command{
|
|||
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"),
|
||||
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"),
|
||||
Host: viper.GetString("miniflux_host"),
|
||||
Token: viper.GetString("miniflux_token"),
|
||||
FeedId: viper.GetInt64("miniflux_feed_id"),
|
||||
FeedFilter: &miniflux.Filter{},
|
||||
}
|
||||
|
||||
app.Archive(minifluxConfig, serviceConfig)
|
||||
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"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue