Skip to content

Commit

Permalink
Add --text option for send.
Browse files Browse the repository at this point in the history
This matches the python wormhole --text option.

Fixes #6
  • Loading branch information
psanford committed Feb 22, 2020
1 parent ecefcfb commit 5bac0c5
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand All @@ -16,8 +17,9 @@ import (
)

var (
codeLen int
codeFlag string
codeLen int
codeFlag string
sendTextFlag string
)

func sendCommand() *cobra.Command {
Expand Down Expand Up @@ -50,6 +52,7 @@ func sendCommand() *cobra.Command {
cmd.Flags().BoolVarP(&verify, "verify", "v", false, "display verification string (and wait for approval)")
cmd.Flags().IntVarP(&codeLen, "code-length", "c", 0, "length of code (in bytes/words)")
cmd.Flags().StringVar(&codeFlag, "code", "", "human-generated code phrase")
cmd.Flags().StringVar(&sendTextFlag, "text", "", "text message to send, instead of a file.\nUse '-' to read from stdin")
cmd.Flags().BoolVar(&hideProgressBar, "hide-progress", false, "suppress progress-bar display")

return &cmd
Expand Down Expand Up @@ -195,14 +198,24 @@ func sendDir(dirpath string) {
func sendText() {
c := newClient()

reader := bufio.NewReader(os.Stdin)
fmt.Print("Text to send: ")
msg, _ := reader.ReadString('\n')
var msg string
if sendTextFlag == "-" {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
bail("Read stdin err: %s", err)
}
msg = string(data)
} else if sendTextFlag != "" {
msg = sendTextFlag
} else {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Text to send: ")
msg, _ := reader.ReadString('\n')

msg = strings.TrimSpace(msg)
msg = strings.TrimSpace(msg)
}

ctx := context.Background()

code, status, err := c.SendText(ctx, msg, wormhole.WithCode(codeFlag))
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 5bac0c5

Please sign in to comment.