From 55425451652d9153a2d86918f477c38eb8653453 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 27 Jul 2016 17:52:21 -0700 Subject: [PATCH] CLI: move most top-level args down into the subcommand So instead of "wormhole --verify send", use "wormhole send --verify". The full set of arguments that were moved down: * --code-length= * --verify * --hide-progress * --no-listen * --tor The following remain as top-level arguments (which should appear after "wormhole" and before the subcommand): * --relay-url= * --transit-helper= * --dump-timing= * --version --- README.md | 12 ++++----- src/wormhole/cli/cli.py | 42 ++++++++++++------------------- src/wormhole/test/test_args.py | 20 +++++++-------- src/wormhole/test/test_scripts.py | 4 +-- 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 23db93c..420480b 100644 --- a/README.md +++ b/README.md @@ -149,15 +149,13 @@ provide information about alternatives. ## CLI tool -* `wormhole send --text TEXT` -* `wormhole send FILENAME` -* `wormhole send DIRNAME` -* `wormhole receive` +* `wormhole send [args] --text TEXT` +* `wormhole send [args] FILENAME` +* `wormhole send [args] DIRNAME` +* `wormhole receive [args]` -Both commands accept: +Both commands accept additional arguments to influence their behavior: -* `--relay-url URL` : override the rendezvous server URL -* `--transit-helper tcp:HOST:PORT`: override the Transit Relay * `--code-length WORDS`: use more or fewer than 2 words for the code * `--verify` : print (and ask user to compare) extra verification string diff --git a/src/wormhole/cli/cli.py b/src/wormhole/cli/cli.py index 09623d5..2935c89 100644 --- a/src/wormhole/cli/cli.py +++ b/src/wormhole/cli/cli.py @@ -48,27 +48,8 @@ class AliasedGroup(click.Group): return click.Group.get_command(self, ctx, cmd_name) -TopArgs = _compose( - click.option("-c", "--code-length", default=2, metavar="NUMWORDS", - help="length of code (in bytes/words)", - ), - click.option("-v", "--verify", is_flag=True, default=False, - help="display verification string (and wait for approval)", - ), - click.option("--hide-progress", is_flag=True, default=False, - help="supress progress-bar display", - ), - click.option("--no-listen", is_flag=True, default=False, - help="(debug) don't open a listening socket for Transit", - ), - click.option("--tor", is_flag=True, default=False, - help="use Tor when connecting", - ), -) - # top-level command ("wormhole ...") @click.group(cls=AliasedGroup) -@TopArgs @click.option( "--relay-url", default=public_relay.RENDEZVOUS_RELAY, metavar="URL", @@ -90,8 +71,7 @@ TopArgs = _compose( version=__version__, ) @click.pass_context -def wormhole(context, tor, no_listen, dump_timing, hide_progress, - verify, code_length, transit_helper, relay_url): +def wormhole(context, dump_timing, transit_helper, relay_url): """ Create a Magic Wormhole and communicate through it. @@ -100,13 +80,8 @@ def wormhole(context, tor, no_listen, dump_timing, hide_progress, anyone who doesn't use the same code. """ context.obj = cfg = Config() - cfg.tor = tor - cfg.listen = not no_listen cfg.relay_url = relay_url cfg.transit_helper = transit_helper - cfg.code_length = code_length - cfg.verify = verify - cfg.hide_progress = hide_progress cfg.dump_timing = dump_timing @@ -147,6 +122,21 @@ CommonArgs = _compose( click.option("-0", "zeromode", default=False, is_flag=True, help="enable no-code anything-goes mode", ), + click.option("-c", "--code-length", default=2, metavar="NUMWORDS", + help="length of code (in bytes/words)", + ), + click.option("-v", "--verify", is_flag=True, default=False, + help="display verification string (and wait for approval)", + ), + click.option("--hide-progress", is_flag=True, default=False, + help="supress progress-bar display", + ), + click.option("--listen/--no-listen", default=True, + help="(debug) don't open a listening socket for Transit", + ), + click.option("--tor", is_flag=True, default=False, + help="use Tor when connecting", + ), ) # wormhole send (or "wormhole tx") diff --git a/src/wormhole/test/test_args.py b/src/wormhole/test/test_args.py index 6070372..b8dbe6e 100644 --- a/src/wormhole/test/test_args.py +++ b/src/wormhole/test/test_args.py @@ -33,7 +33,7 @@ class Send(unittest.TestCase): self.assertEqual(cfg.text, u"hi") def test_nolisten(self): - cfg = config("--no-listen", "send", "fn") + cfg = config("send", "--no-listen", "fn") self.assertEqual(cfg.listen, False) def test_code(self): @@ -41,7 +41,7 @@ class Send(unittest.TestCase): self.assertEqual(cfg.code, u"1-abc") def test_code_length(self): - cfg = config("-c", "3", "send", "fn") + cfg = config("send", "-c", "3", "fn") self.assertEqual(cfg.code_length, 3) def test_dump_timing(self): @@ -49,15 +49,15 @@ class Send(unittest.TestCase): self.assertEqual(cfg.dump_timing, "tx.json") def test_hide_progress(self): - cfg = config("--hide-progress", "send", "fn") + cfg = config("send", "--hide-progress", "fn") self.assertEqual(cfg.hide_progress, True) def test_tor(self): - cfg = config("--tor", "send", "fn") + cfg = config("send", "--tor", "fn") self.assertEqual(cfg.tor, True) def test_verify(self): - cfg = config("--verify", "send", "fn") + cfg = config("send", "--verify", "fn") self.assertEqual(cfg.verify, True) def test_zeromode(self): @@ -83,7 +83,7 @@ class Receive(unittest.TestCase): self.assertEqual(cfg.zeromode, False) def test_nolisten(self): - cfg = config("--no-listen", "receive") + cfg = config("receive", "--no-listen") self.assertEqual(cfg.listen, False) def test_code(self): @@ -91,7 +91,7 @@ class Receive(unittest.TestCase): self.assertEqual(cfg.code, u"1-abc") def test_code_length(self): - cfg = config("-c", "3", "receive") + cfg = config("receive", "-c", "3") self.assertEqual(cfg.code_length, 3) def test_dump_timing(self): @@ -99,15 +99,15 @@ class Receive(unittest.TestCase): self.assertEqual(cfg.dump_timing, "tx.json") def test_hide_progress(self): - cfg = config("--hide-progress", "receive") + cfg = config("receive", "--hide-progress") self.assertEqual(cfg.hide_progress, True) def test_tor(self): - cfg = config("--tor", "receive") + cfg = config("receive", "--tor") self.assertEqual(cfg.tor, True) def test_verify(self): - cfg = config("--verify", "receive") + cfg = config("receive", "--verify") self.assertEqual(cfg.verify, True) def test_zeromode(self): diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index 66be1e5..3a45b0d 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -298,10 +298,10 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): content_args = [send_cfg.what] send_args = [ - '--hide-progress', '--relay-url', self.relayurl, '--transit-helper', '', 'send', + '--hide-progress', '--code', send_cfg.code, ] + content_args @@ -311,10 +311,10 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): env=dict(LC_ALL="en_US.UTF-8", LANG="en_US.UTF-8"), ) recv_args = [ - '--hide-progress', '--relay-url', self.relayurl, '--transit-helper', '', 'receive', + '--hide-progress', '--accept-file', recv_cfg.code, ]