123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- package cmd
- import (
- "errors"
- "github.com/mudler/edgevpn/pkg/edgevpn"
- "github.com/urfave/cli"
- )
- func cliNamePath(c *cli.Context) (name, path string, err error) {
- name = c.Args().Get(0)
- path = c.Args().Get(1)
- if name == "" && c.String("name") == "" {
- err = errors.New("Either a file UUID as first argument or with --name needs to be provided")
- return
- }
- if path == "" && c.String("path") == "" {
- err = errors.New("Either a file UUID as first argument or with --name needs to be provided")
- return
- }
- if c.String("name") != "" {
- name = c.String("name")
- }
- if c.String("path") != "" {
- path = c.String("path")
- }
- return name, path, nil
- }
- func FileSend() cli.Command {
- return cli.Command{
- Name: "file-send",
- Aliases: []string{"fs"},
- Usage: "Serve a file to the network",
- Description: `Serve a file to the network without connecting over VPN`,
- UsageText: "edgevpn file-send unique-id /src/path",
- Flags: append(CommonFlags,
- cli.StringFlag{
- Name: "name",
- Required: true,
- Usage: `Unique name of the file to be served over the network.
- This is also the ID used to refer when receiving it.`,
- },
- cli.StringFlag{
- Name: "path",
- Usage: `File to serve`,
- Required: true,
- },
- ),
- Action: func(c *cli.Context) error {
- name, path, err := cliNamePath(c)
- if err != nil {
- return err
- }
- e := edgevpn.New(cliToOpts(c)...)
- displayStart(e)
- ledger, err := e.Ledger()
- if err != nil {
- return err
- }
- // Join the node to the network, using our ledger
- e.SendFile(ledger, name, path)
- // Join the node to the network, using our ledger
- if err := e.Join(); err != nil {
- return err
- }
- for {
- }
- },
- }
- }
- func FileReceive() cli.Command {
- return cli.Command{
- Name: "file-receive",
- Aliases: []string{"fr"},
- Usage: "Receive a file which is served from the network",
- Description: `Receive a file from the network without connecting over VPN`,
- UsageText: "edgevpn file-receive unique-id /dst/path",
- Flags: append(CommonFlags,
- cli.StringFlag{
- Name: "name",
- Usage: `Unique name of the file to be received over the network.`,
- },
- cli.StringFlag{
- Name: "path",
- Usage: `Destination where to save the file`,
- },
- ),
- Action: func(c *cli.Context) error {
- name, path, err := cliNamePath(c)
- if err != nil {
- return err
- }
- e := edgevpn.New(cliToOpts(c)...)
- displayStart(e)
- // Join the node to the network, using our ledger
- if err := e.Join(); err != nil {
- return err
- }
- ledger, _ := e.Ledger()
- return e.ReceiveFile(ledger, name, path)
- },
- }
- }
|