From: David Stainton Date: Thu, 18 Jun 2015 17:50:47 +0000 (-0700) Subject: Add boiler plate for magic-folder subcommand X-Git-Url: https://git.rkrishnan.org/vdrive//%22?a=commitdiff_plain;h=7d6b9f823f3490a5385b9582d29a7eebc65a1120;p=tahoe-lafs%2Ftahoe-lafs.git Add boiler plate for magic-folder subcommand here we also: - add the synopsis for the create command - add the argument parser for the create command --- diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py new file mode 100644 index 00000000..94436348 --- /dev/null +++ b/src/allmydata/scripts/magic_folder_cli.py @@ -0,0 +1,71 @@ + +from twisted.python import usage, failure +from allmydata.scripts.common import BaseOptions +from .common import BaseOptions, BasedirOptions + +class CreateOptions(BasedirOptions): + nickname = None + localdir = None + def parseArgs(self, alias, nickname=None, localdir=None): + BasedirOptions.parseArgs(self) + self.alias = alias + self.nickname = nickname + self.localdir = localdir + if self.nickname and not self.localdir: + raise usage.UsageError("must provide both") + synopsis = "MAGIC_ALIAS: [NICKNAME LOCALDIR]" + +def create(options): + pass + +class InviteOptions(BasedirOptions): + pass + +def invite(options): + pass + +class JoinOptions(BasedirOptions): + pass + +def join(options): + pass + +class MagicFolderCommand(BaseOptions): + subCommands = [ + ["create", None, CreateOptions, "Create a Magic-Folder."], + ["invite", None, InviteOptions, "Invite someone to a Magic-Folder."], + ["join", None, JoinOptions, "Join a Magic-Folder."], + ] + def postOptions(self): + if not hasattr(self, 'subOptions'): + raise usage.UsageError("must specify a subcommand") + def getSynopsis(self): + return "Usage: tahoe [global-options] magic SUBCOMMAND" + def getUsage(self, width=None): + t = BaseOptions.getUsage(self, width) + t += """\ +Please run e.g. 'tahoe magic-folder create --help' for more details on each +subcommand. +""" + return t + +subDispatch = { + "create": create, + "invite": invite, + "join": join, +} + +def do_magic_folder(options): + so = options.subOptions + so.stdout = options.stdout + so.stderr = options.stderr + f = subDispatch[options.subCommand] + return f(so) + +subCommands = [ + ["magic-folder", None, MagicFolderCommand, "magic-folder subcommands: use 'tahoe magic-folder' for a list."], +] + +dispatch = { + "magic-folder": do_magic_folder, +} diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py index c331eee7..0afb1243 100644 --- a/src/allmydata/scripts/runner.py +++ b/src/allmydata/scripts/runner.py @@ -5,7 +5,7 @@ from cStringIO import StringIO from twisted.python import usage from allmydata.scripts.common import get_default_nodedir -from allmydata.scripts import debug, create_node, startstop_node, cli, keygen, stats_gatherer, admin +from allmydata.scripts import debug, create_node, startstop_node, cli, keygen, stats_gatherer, admin, magic_folder_cli from allmydata.util.encodingutil import quote_output, quote_local_unicode_path, get_io_encoding def GROUP(s): @@ -45,6 +45,7 @@ class Options(usage.Options): + debug.subCommands + GROUP("Using the filesystem") + cli.subCommands + + magic_folder_cli.subCommands ) optFlags = [ @@ -143,6 +144,8 @@ def runner(argv, rc = admin.dispatch[command](so) elif command in cli.dispatch: rc = cli.dispatch[command](so) + elif command in magic_folder_cli.dispatch: + rc = magic_folder_cli.dispatch[command](so) elif command in ac_dispatch: rc = ac_dispatch[command](so, stdout, stderr) else: