edge/cmd/cli/command/cast/status.go

47 lines
914 B
Go

package cast
import (
"context"
"log"
"time"
"forge.cadoles.com/arcad/edge/pkg/module/cast"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func StatusCommand() *cli.Command {
return &cli.Command{
Name: "status",
Usage: "Retrieve casting device status",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "device",
Aliases: []string{"d"},
Required: true,
},
&cli.DurationFlag{
Name: "timeout",
Aliases: []string{"t"},
Value: 10 * time.Second,
},
},
Action: func(ctx *cli.Context) error {
device := ctx.String("device")
timeout := ctx.Duration("timeout")
getStatusCtx, cancel := context.WithTimeout(ctx.Context, timeout)
defer cancel()
status, err := cast.GetStatus(getStatusCtx, device)
if err != nil {
return errors.WithStack(err)
}
log.Printf("[STATUS] %s %s", status.Title(), status.State())
return nil
},
}
}