54 lines
1.1 KiB
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 Status() *cli.Command {
|
||
|
return &cli.Command{
|
||
|
Name: "status",
|
||
|
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.Status(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
|
||
|
},
|
||
|
}
|
||
|
}
|