arcast/internal/command/client/reset.go

54 lines
1.1 KiB
Go

package client
import (
"os"
"forge.cadoles.com/arcad/arcast/internal/command/client/flag"
"forge.cadoles.com/arcad/arcast/pkg/client"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"gitlab.com/wpetit/goweb/cli/format"
)
func Reset() *cli.Command {
return &cli.Command{
Name: "reset",
Flags: flag.ComposeFlags(
playerFlags...,
),
Action: func(ctx *cli.Context) error {
baseFlags := flag.GetBaseFlags(ctx)
statuses := make([]wrappedStatus, 0)
err := forEachPlayer(ctx, func(cl *client.Client, playerAddr string) error {
status, err := cl.Reset(ctx.Context, playerAddr)
if err != nil {
return errors.Wrap(err, "could not cast")
}
statuses = append(statuses, wrappedStatus{
Status: status.Status,
URL: status.URL,
Title: status.Title,
ID: status.ID,
Address: playerAddr,
})
return nil
})
if err != nil {
return errors.WithStack(err)
}
hints := wrappedStatusHints(baseFlags.OutputMode)
if err := format.Write(baseFlags.Format, os.Stdout, hints, AsAnySlice(statuses...)...); err != nil {
return errors.WithStack(err)
}
return nil
},
}
}