0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

fork Antonito/gfile

This commit is contained in:
Zack Scholl 2019-04-08 07:14:54 -07:00
parent 01f30b3a99
commit e222dbd1e3
41 changed files with 2121 additions and 0 deletions

45
cmd/receive/cmd.go Normal file
View file

@ -0,0 +1,45 @@
package receive
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/antonito/gfile/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",
},
},
}
}