1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00
schollz_croc/cmd/receive/cmd.go
2019-04-10 07:25:29 -07:00

45 lines
827 B
Go

package receive
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/schollz/croc/v5/src/webrtc/pkg/session/receiver"
"gopkg.in/urfave/cli.v1"
)
func handler(c *cli.Context) error {
output := c.String("output")
if output == "" {
return fmt.Errorf("output parameter missing")
}
f, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer f.Close()
sess := receiver.NewWith(receiver.Config{
Stream: f,
})
return sess.Start()
}
// New creates the command
func New() cli.Command {
log.Traceln("Installing 'receive' command")
return cli.Command{
Name: "receive",
Aliases: []string{"r"},
Usage: "Receive a file",
Action: handler,
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Usage: "Output",
},
},
}
}