package cast import ( "context" "log" "time" "github.com/barnybug/go-cast/discovery" "github.com/pkg/errors" "github.com/urfave/cli/v2" ) func ScanCommand() *cli.Command { return &cli.Command{ Name: "scan", Usage: "Scan network for casting devices", Flags: []cli.Flag{}, Action: func(ctx *cli.Context) error { service := discovery.NewService(ctx.Context) defer service.Stop() go func() { if err := service.Run(ctx.Context, time.Second); err != nil && !errors.Is(err, context.DeadlineExceeded) { log.Fatalf("%+v", errors.WithStack(err)) } }() found := service.Found() for device := range found { log.Printf("[DEVICE] %s %s %s:%d", device.Uuid(), device.Name(), device.IP().String(), device.Port()) } return nil }, } }