cli: start factoring out args into common sets
This commit is contained in:
parent
37b8ccbe4f
commit
e6b38ecacc
|
@ -30,6 +30,13 @@ class Config(object):
|
||||||
self.stdout = stdout
|
self.stdout = stdout
|
||||||
self.stderr = stderr
|
self.stderr = stderr
|
||||||
|
|
||||||
|
def _compose(*decorators):
|
||||||
|
def decorate(f):
|
||||||
|
for d in reversed(decorators):
|
||||||
|
f = d(f)
|
||||||
|
return f
|
||||||
|
return decorate
|
||||||
|
|
||||||
|
|
||||||
ALIASES = {
|
ALIASES = {
|
||||||
"tx": "send",
|
"tx": "send",
|
||||||
|
@ -41,8 +48,27 @@ class AliasedGroup(click.Group):
|
||||||
return click.Group.get_command(self, ctx, cmd_name)
|
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 ...")
|
# top-level command ("wormhole ...")
|
||||||
@click.group(cls=AliasedGroup)
|
@click.group(cls=AliasedGroup)
|
||||||
|
@TopArgs
|
||||||
@click.option(
|
@click.option(
|
||||||
"--relay-url", default=public_relay.RENDEZVOUS_RELAY,
|
"--relay-url", default=public_relay.RENDEZVOUS_RELAY,
|
||||||
metavar="URL",
|
metavar="URL",
|
||||||
|
@ -53,33 +79,12 @@ class AliasedGroup(click.Group):
|
||||||
metavar="tcp:HOST:PORT",
|
metavar="tcp:HOST:PORT",
|
||||||
help="transit relay to use",
|
help="transit relay to use",
|
||||||
)
|
)
|
||||||
@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 (and wait for acceptance of) verification string",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--hide-progress", is_flag=True, default=False,
|
|
||||||
help="supress progress-bar display",
|
|
||||||
)
|
|
||||||
@click.option(
|
@click.option(
|
||||||
"--dump-timing", type=type(u""), # TODO: hide from --help output
|
"--dump-timing", type=type(u""), # TODO: hide from --help output
|
||||||
default=None,
|
default=None,
|
||||||
metavar="FILE.json",
|
metavar="FILE.json",
|
||||||
help="(debug) write timing data to file",
|
help="(debug) write timing data to file",
|
||||||
)
|
)
|
||||||
@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",
|
|
||||||
)
|
|
||||||
@click.version_option(
|
@click.version_option(
|
||||||
message="magic-wormhole %(version)s",
|
message="magic-wormhole %(version)s",
|
||||||
version=__version__,
|
version=__version__,
|
||||||
|
@ -138,12 +143,15 @@ def _dispatch_command(reactor, cfg, command):
|
||||||
cfg.timing.write(cfg.dump_timing, stderr)
|
cfg.timing.write(cfg.dump_timing, stderr)
|
||||||
|
|
||||||
|
|
||||||
|
CommonArgs = _compose(
|
||||||
|
click.option("-0", "zeromode", default=False, is_flag=True,
|
||||||
|
help="enable no-code anything-goes mode",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
# wormhole send (or "wormhole tx")
|
# wormhole send (or "wormhole tx")
|
||||||
@wormhole.command()
|
@wormhole.command()
|
||||||
@click.option(
|
@CommonArgs
|
||||||
"-0", "zeromode", default=False, is_flag=True,
|
|
||||||
help="enable no-code anything-goes mode",
|
|
||||||
)
|
|
||||||
@click.option(
|
@click.option(
|
||||||
"--code", metavar="CODE",
|
"--code", metavar="CODE",
|
||||||
help="human-generated code phrase",
|
help="human-generated code phrase",
|
||||||
|
@ -172,10 +180,7 @@ def go(f, cfg):
|
||||||
|
|
||||||
# wormhole receive (or "wormhole rx")
|
# wormhole receive (or "wormhole rx")
|
||||||
@wormhole.command()
|
@wormhole.command()
|
||||||
@click.option(
|
@CommonArgs
|
||||||
"-0", "zeromode", default=False, is_flag=True,
|
|
||||||
help="enable no-code anything-goes mode",
|
|
||||||
)
|
|
||||||
@click.option(
|
@click.option(
|
||||||
"--only-text", "-t", is_flag=True,
|
"--only-text", "-t", is_flag=True,
|
||||||
help="refuse file transfers, only accept text transfers",
|
help="refuse file transfers, only accept text transfers",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user