blocky/cmd/lists.go

45 lines
886 B
Go
Raw Permalink Normal View History

2021-02-08 21:56:58 +01:00
package cmd
import (
"context"
"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"
)
// NewListsCommand creates new command instance
2021-02-08 21:56:58 +01:00
func NewListsCommand() *cobra.Command {
c := &cobra.Command{
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",
RunE: refreshList,
2021-02-08 21:56:58 +01:00
}
}
func refreshList(_ *cobra.Command, _ []string) error {
client, err := api.NewClientWithResponses(apiURL())
2021-02-08 21:56:58 +01:00
if err != nil {
return fmt.Errorf("can't create client: %w", err)
2021-02-08 21:56:58 +01:00
}
resp, err := client.ListRefreshWithResponse(context.Background())
if err != nil {
return fmt.Errorf("can't execute %w", err)
}
return printOkOrError(resp, string(resp.Body))
2021-02-08 21:56:58 +01:00
}