mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 21:43:09 +00:00
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
This commit is contained in:
parent
b448905b50
commit
8f3c04ab8c
71
src/allmydata/scripts/magic_folder_cli.py
Normal file
71
src/allmydata/scripts/magic_folder_cli.py
Normal file
@ -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,
|
||||
}
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user