receive.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package cmd
  2. import (
  3. "github.com/claudiodangelis/qrcp/config"
  4. "github.com/claudiodangelis/qrcp/logger"
  5. "github.com/claudiodangelis/qrcp/qr"
  6. "github.com/claudiodangelis/qrcp/server"
  7. "github.com/spf13/cobra"
  8. )
  9. func receiveCmdFunc(command *cobra.Command, args []string) error {
  10. log := logger.New(quietFlag)
  11. // Load configuration
  12. cfg, err := config.New(interfaceFlag, portFlag, pathFlag, fqdnFlag, keepaliveFlag, listallinterfacesFlag)
  13. if err != nil {
  14. return err
  15. }
  16. // Create the server
  17. srv, err := server.New(&cfg)
  18. if err != nil {
  19. return err
  20. }
  21. // Sets the output directory
  22. if err := srv.ReceiveTo(outputFlag); err != nil {
  23. return err
  24. }
  25. // Prints the URL to scan to screen
  26. log.Print("Scan the following URL with a QR reader to start the file transfer:")
  27. log.Print(srv.ReceiveURL)
  28. // Renders the QR
  29. qr.RenderString(srv.ReceiveURL)
  30. if err := srv.Wait(); err != nil {
  31. return err
  32. }
  33. return nil
  34. }
  35. var receiveCmd = &cobra.Command{
  36. Use: "receive",
  37. Aliases: []string{"r"},
  38. Short: "Receive one or more files",
  39. Long: "Receive one or more files. If not specified with the --output flag, the current working directory will be used as a destination.",
  40. Example: `# Receive files in the current directory
  41. qrcp receive
  42. # Receive files in a specific directory
  43. qrcp receive --output /tmp
  44. `,
  45. RunE: receiveCmdFunc,
  46. }