2021-02-08 21:56:58 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-09-09 19:30:55 +02:00
|
|
|
"context"
|
2022-05-06 22:34:08 +02:00
|
|
|
"fmt"
|
2021-02-08 21:56:58 +01:00
|
|
|
|
2021-08-25 22:06:34 +02:00
|
|
|
"github.com/0xERR0R/blocky/api"
|
2021-02-08 21:56:58 +01:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2021-02-26 13:45:57 +01:00
|
|
|
// NewListsCommand creates new command instance
|
2021-02-08 21:56:58 +01:00
|
|
|
func NewListsCommand() *cobra.Command {
|
|
|
|
c := &cobra.Command{
|
2024-05-26 20:45:30 +02:00
|
|
|
Use: "lists",
|
|
|
|
Short: "lists operations",
|
|
|
|
PersistentPreRunE: initConfigPreRun,
|
2021-02-08 21:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
c.AddCommand(newRefreshCommand())
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRefreshCommand() *cobra.Command {
|
|
|
|
return &cobra.Command{
|
|
|
|
Use: "refresh",
|
|
|
|
Short: "refreshes all lists",
|
2022-05-06 22:34:08 +02:00
|
|
|
RunE: refreshList,
|
2021-02-08 21:56:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-06 22:34:08 +02:00
|
|
|
func refreshList(_ *cobra.Command, _ []string) error {
|
2023-09-09 19:30:55 +02:00
|
|
|
client, err := api.NewClientWithResponses(apiURL())
|
2021-02-08 21:56:58 +01:00
|
|
|
if err != nil {
|
2023-09-09 19:30:55 +02:00
|
|
|
return fmt.Errorf("can't create client: %w", err)
|
2021-02-08 21:56:58 +01:00
|
|
|
}
|
|
|
|
|
2023-09-09 19:30:55 +02:00
|
|
|
resp, err := client.ListRefreshWithResponse(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't execute %w", err)
|
|
|
|
}
|
2022-05-10 09:09:50 +02:00
|
|
|
|
2023-09-30 22:13:01 +02:00
|
|
|
return printOkOrError(resp, string(resp.Body))
|
2021-02-08 21:56:58 +01:00
|
|
|
}
|