package cast import ( "context" "time" "forge.cadoles.com/arcad/edge/pkg/module/cast" "github.com/pkg/errors" "github.com/urfave/cli/v2" ) func LoadURLCommand() *cli.Command { return &cli.Command{ Name: "load-url", Usage: "Load `URL` in casting device", Flags: []cli.Flag{ &cli.StringFlag{ Name: "device", Aliases: []string{"d"}, Required: true, }, &cli.StringFlag{ Name: "url", Aliases: []string{"u"}, Required: true, }, &cli.DurationFlag{ Name: "timeout", Aliases: []string{"t"}, Value: 10 * time.Second, }, }, Action: func(ctx *cli.Context) error { device := ctx.String("device") url := ctx.String("url") timeout := ctx.Duration("timeout") timeoutCtx, cancel := context.WithTimeout(ctx.Context, timeout) defer cancel() if err := cast.StopCast(timeoutCtx, device); err != nil { return errors.WithStack(err) } if err := cast.LoadURL(timeoutCtx, device, url); err != nil { return errors.WithStack(err) } return nil }, } }