]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add boiler plate for magic-folder subcommand
authorDavid Stainton <dstainton415@gmail.com>
Thu, 18 Jun 2015 17:50:47 +0000 (10:50 -0700)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 20 Jul 2015 23:42:34 +0000 (00:42 +0100)
here we also:
- add the synopsis for the create command
- add the argument parser for the create command

src/allmydata/scripts/magic_folder_cli.py [new file with mode: 0644]
src/allmydata/scripts/runner.py

diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py
new file mode 100644 (file)
index 0000000..9443634
--- /dev/null
@@ -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,
+}
index c331eee72684ec1ac4a8c8e01da7ed0ad2557e0d..0afb12431500f3a4c81a21c5f43a5602a3bf4b46 100644 (file)
@@ -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: