chore: add cast commands for testing purpose
This commit is contained in:
@ -200,7 +200,7 @@ func getServerModules(bus bus.Bus, ds storage.DocumentStore, bs storage.BlobStor
|
||||
},
|
||||
),
|
||||
appModule.ModuleFactory(appModuleMemory.NewRepository(
|
||||
func(ctx context.Context, i app.ID) (string, error) {
|
||||
func(ctx context.Context, id app.ID, from string) (string, error) {
|
||||
if strings.HasPrefix(address, ":") {
|
||||
address = "0.0.0.0" + address
|
||||
}
|
||||
|
40
cmd/cli/command/cast/load_url.go
Normal file
40
cmd/cli/command/cast/load_url.go
Normal file
@ -0,0 +1,40 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"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,
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
device := ctx.String("device")
|
||||
url := ctx.String("url")
|
||||
|
||||
if err := cast.StopCast(ctx.Context, device); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := cast.LoadURL(ctx.Context, device, url); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
16
cmd/cli/command/cast/root.go
Normal file
16
cmd/cli/command/cast/root.go
Normal file
@ -0,0 +1,16 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Root() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "cast",
|
||||
Usage: "Cast related commands",
|
||||
Subcommands: []*cli.Command{
|
||||
ScanCommand(),
|
||||
LoadURLCommand(),
|
||||
},
|
||||
}
|
||||
}
|
37
cmd/cli/command/cast/scan.go
Normal file
37
cmd/cli/command/cast/scan.go
Normal file
@ -0,0 +1,37 @@
|
||||
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
|
||||
},
|
||||
}
|
||||
}
|
@ -3,8 +3,9 @@ package main
|
||||
import (
|
||||
"forge.cadoles.com/arcad/edge/cmd/cli/command"
|
||||
"forge.cadoles.com/arcad/edge/cmd/cli/command/app"
|
||||
"forge.cadoles.com/arcad/edge/cmd/cli/command/cast"
|
||||
)
|
||||
|
||||
func main() {
|
||||
command.Main(app.Root())
|
||||
command.Main(app.Root(), cast.Root())
|
||||
}
|
||||
|
Reference in New Issue
Block a user