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

48 lines
925 B
Go

package send
import (
"fmt"
"os"
"github.com/schollz/croc/v5/src/webrtc/pkg/session/common"
"github.com/schollz/croc/v5/src/webrtc/pkg/session/sender"
log "github.com/sirupsen/logrus"
"gopkg.in/urfave/cli.v1"
)
func handler(c *cli.Context) error {
fileToSend := c.String("file")
if fileToSend == "" {
return fmt.Errorf("file parameter missing")
}
f, err := os.Open(fileToSend)
if err != nil {
return err
}
defer f.Close()
sess := sender.NewWith(sender.Config{
Stream: f,
Configuration: common.Configuration{
OnCompletion: func() {
},
},
})
return sess.Start()
}
// New creates the command
func New() cli.Command {
log.Traceln("Installing 'send' command")
return cli.Command{
Name: "send",
Aliases: []string{"s"},
Usage: "Sends a file",
Action: handler,
Flags: []cli.Flag{
cli.StringFlag{
Name: "file, f",
Usage: "Send content of file `FILE`",
},
},
}
}