improve "wormhole send" args for text-vs-file

There are now three ways to invoke send:

* "wormhole send": ask for a text message
* "wormhole send FILENAME": send a file
* "wormhole send --text TEXT": send text message
This commit is contained in:
Brian Warner 2015-10-03 23:25:11 -07:00
parent e7e5c2d079
commit 56f8327c71
2 changed files with 20 additions and 11 deletions

View File

@ -11,7 +11,20 @@ def send(args):
from ..blocking.transit import TransitSender
from .progress import start_progress, update_progress, finish_progress
if os.path.isfile(args.what):
text = args.text
if not text and not args.what:
text = six.moves.input("Text to send: ")
if text is not None:
sending_message = True
print("Sending text message (%d bytes)" % len(text))
phase1 = {
"message": text,
}
else:
if not os.path.isfile(args.what):
print("Cannot send: no file named '%s'" % args.what)
return 1
# we're sending a file
sending_message = False
filesize = os.stat(args.what).st_size
@ -28,12 +41,6 @@ def send(args):
"relay_connection_hints": transit_sender.get_relay_hints(),
},
}
else:
sending_message = True
print("Sending text message (%d bytes)" % len(args.what))
phase1 = {
"message": args.what,
}
w = Wormhole(APPID, args.relay_url)
if args.zeromode:

View File

@ -65,12 +65,14 @@ sp_restart.set_defaults(func=cmd_server.restart_server)
# CLI: send
p = subparsers.add_parser("send",
description="Send text message or file",
usage="wormhole send TEXT|FILENAME")
usage="wormhole send [FILENAME]")
p.add_argument("--text", metavar="MESSAGE",
help="text message to send, instead of a file")
p.add_argument("--code", metavar="CODE", help="human-generated code phrase")
p.add_argument("-0", dest="zeromode", action="store_true",
help="enable no-code anything-goes mode")
p.add_argument("what", metavar="TEXT|FILENAME",
help="the message to send (a string), or a filename")
p.add_argument("what", nargs="?", default=None, metavar="[FILENAME]",
help="the file to send")
p.set_defaults(func=cmd_send.send)
# CLI: receive
@ -82,7 +84,7 @@ p.add_argument("-0", dest="zeromode", action="store_true",
p.add_argument("-t", "--only-text", dest="only_text", action="store_true",
help="refuse file transfers, only accept text transfers")
p.add_argument("--accept-file", dest="accept_file", action="store_true",
help="accept file transfer with prompting")
help="accept file transfer with asking for confirmation")
p.add_argument("-o", "--output-file", default=None, metavar="FILENAME",
help=dedent("""\
The file to create, overriding the filename suggested by the