feat: initial commit
This commit is contained in:
53
internal/command/client/reset.go
Normal file
53
internal/command/client/reset.go
Normal file
@ -0,0 +1,53 @@
|
||||
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
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user