]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/scripts/cli.py
Remove -u shortcut for 'tahoe ls --uri' which clashes with --node-url. fixes ticket...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / cli.py
index 56a1b88e6ca639a42e8c1ad311cd49c088eeb9f7..722c8d983b5b55694841f62eb0904ee7b4ea6f46 100644 (file)
@@ -1,34 +1,31 @@
-
-import os.path, re, sys
+import os.path, re, fnmatch
 from twisted.python import usage
-from allmydata.scripts.common import BaseOptions
+from allmydata.scripts.common import get_aliases, get_default_nodedir, \
+     DEFAULT_ALIAS, BaseOptions
+from allmydata.util.encodingutil import argv_to_unicode, argv_to_abspath, quote_local_unicode_path
+
+NODEURL_RE=re.compile("http(s?)://([^:]*)(:([1-9][0-9]*))?")
 
-NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?")
+_default_nodedir = get_default_nodedir()
 
-class VDriveOptions(BaseOptions, usage.Options):
+class FilesystemOptions(BaseOptions):
     optParameters = [
-        ["node-directory", "d", "~/.tahoe",
-         "Look here to find out which Tahoe node should be used for all "
-         "operations. The directory should either contain a full Tahoe node, "
-         "or a file named node.url which points to some other Tahoe node. "
-         "It should also contain a file named root_dir.cap which contains "
-         "the root dirnode URI that should be used."
-         ],
         ["node-url", "u", None,
-         "URL of the tahoe node to use, a URL like \"http://127.0.0.1:8123\". "
+         "Specify the URL of the Tahoe gateway node, such as "
+         "'http://127.0.0.1:3456'. "
          "This overrides the URL found in the --node-directory ."],
-        ["dir-cap", "r", None,
-         "Which dirnode URI should be used as the 'tahoe' alias."]
+        ["dir-cap", None, None,
+         "Specify which dirnode URI should be used as the 'tahoe' alias."]
         ]
 
     def postOptions(self):
+        self["quiet"] = self.parent["quiet"]
+        if self.parent['node-directory']:
+            self['node-directory'] = argv_to_abspath(self.parent['node-directory'])
+        else:
+            self['node-directory'] = _default_nodedir
+
         # compute a node-url from the existing options, put in self['node-url']
-        if self['node-directory']:
-            if sys.platform == 'win32' and self['node-directory'] == '~/.tahoe':
-                from allmydata.windows import registry
-                self['node-directory'] = registry.get_base_dir_path()
-            else:
-                self['node-directory'] = os.path.expanduser(self['node-directory'])
         if self['node-url']:
             if (not isinstance(self['node-url'], basestring)
                 or not NODEURL_RE.match(self['node-url'])):
@@ -39,252 +36,555 @@ class VDriveOptions(BaseOptions, usage.Options):
         else:
             node_url_file = os.path.join(self['node-directory'], "node.url")
             self['node-url'] = open(node_url_file, "r").read().strip()
+        if self['node-url'][-1] != "/":
+            self['node-url'] += "/"
 
-        aliases = self.get_aliases(self['node-directory'])
+        aliases = get_aliases(self['node-directory'])
         if self['dir-cap']:
-            aliases["tahoe"] = self['dir-cap']
+            aliases[DEFAULT_ALIAS] = self['dir-cap']
         self.aliases = aliases # maps alias name to dircap
 
 
-    def get_aliases(self, nodedir):
-        from allmydata import uri
-        aliases = {}
-        aliasfile = os.path.join(nodedir, "private", "aliases")
-        rootfile = os.path.join(nodedir, "private", "root_dir.cap")
-        try:
-            f = open(rootfile, "r")
-            rootcap = f.read().strip()
-            if rootcap:
-                aliases["tahoe"] = uri.from_string_dirnode(rootcap).to_string()
-        except EnvironmentError:
-            pass
-        try:
-            f = open(aliasfile, "r")
-            for line in f.readlines():
-                line = line.strip()
-                if line.startswith("#"):
-                    continue
-                name, cap = line.split(":", 1)
-                # normalize it: remove http: prefix, urldecode
-                cap = cap.strip()
-                aliases[name] = uri.from_string_dirnode(cap).to_string()
-        except EnvironmentError:
-            pass
-        return aliases
+class MakeDirectoryOptions(FilesystemOptions):
+    optParameters = [
+        ("format", None, None, "Create a directory with the given format: SDMF or MDMF (case-insensitive)"),
+        ]
 
-class MakeDirectoryOptions(VDriveOptions):
     def parseArgs(self, where=""):
-        self.where = where
-    longdesc = """Create a new directory, either unlinked or as a subdirectory."""
+        self.where = argv_to_unicode(where)
+
+        if self['format']:
+            if self['format'].upper() not in ("SDMF", "MDMF"):
+                raise usage.UsageError("%s is an invalid format" % self['format'])
 
-class AddAliasOptions(VDriveOptions):
+    synopsis = "[options] [REMOTE_DIR]"
+    description = """Create a new directory, either unlinked or as a subdirectory."""
+
+class AddAliasOptions(FilesystemOptions):
     def parseArgs(self, alias, cap):
-        self.alias = alias
+        self.alias = argv_to_unicode(alias)
+        if self.alias.endswith(u':'):
+            self.alias = self.alias[:-1]
         self.cap = cap
 
-class ListOptions(VDriveOptions):
+    synopsis = "[options] ALIAS[:] DIRCAP"
+    description = """Add a new alias for an existing directory."""
+
+class CreateAliasOptions(FilesystemOptions):
+    def parseArgs(self, alias):
+        self.alias = argv_to_unicode(alias)
+        if self.alias.endswith(u':'):
+            self.alias = self.alias[:-1]
+
+    synopsis = "[options] ALIAS[:]"
+    description = """Create a new directory and add an alias for it."""
+
+class ListAliasesOptions(FilesystemOptions):
+    synopsis = "[options]"
+    description = """Display a table of all configured aliases."""
+
+class ListOptions(FilesystemOptions):
     optFlags = [
-        ("long", "l", "Use long format: show file sizes, and timestamps"),
-        ("uri", "u", "Show file/directory URIs"),
-        ("readonly-uri", None, "Show readonly file/directory URIs"),
-        ("classify", "F", "Append '/' to directory names, and '*' to mutable"),
-        ("json", None, "Show the raw JSON output"),
+        ("long", "l", "Use long format: show file sizes, and timestamps."),
+        ("uri", None, "Show file/directory URIs."),
+        ("readonly-uri", None, "Show read-only file/directory URIs."),
+        ("classify", "F", "Append '/' to directory names, and '*' to mutable."),
+        ("json", None, "Show the raw JSON output."),
         ]
     def parseArgs(self, where=""):
-        self.where = where
+        self.where = argv_to_unicode(where)
+
+    synopsis = "[options] [PATH]"
+
+    description = """
+    List the contents of some portion of the grid.
+
+    If PATH is omitted, "tahoe:" is assumed.
+
+    When the -l or --long option is used, each line is shown in the
+    following format:
+
+     drwx <size> <date/time> <name in this directory>
+
+    where each of the letters on the left may be replaced by '-'.
+    If 'd' is present, it indicates that the object is a directory.
+    If the 'd' is replaced by a '?', the object type is unknown.
+    'rwx' is a Unix-like permissions mask: if the mask includes 'w',
+    then the object is writeable through its link in this directory
+    (note that the link might be replaceable even if the object is
+    not writeable through the current link).
+    The 'x' is a legacy of Unix filesystems. In Tahoe it is used
+    only to indicate that the contents of a directory can be listed.
+
+    Directories have no size, so their size field is shown as '-'.
+    Otherwise the size of the file, when known, is given in bytes.
+    The size of mutable files or unknown objects is shown as '?'.
 
-    longdesc = """List the contents of some portion of the virtual drive."""
+    The date/time shows when this link in the Tahoe filesystem was
+    last modified.
+    """
 
-class GetOptions(VDriveOptions):
+class GetOptions(FilesystemOptions):
     def parseArgs(self, arg1, arg2=None):
         # tahoe get FOO |less            # write to stdout
         # tahoe get tahoe:FOO |less      # same
         # tahoe get FOO bar              # write to local file
         # tahoe get tahoe:FOO bar        # same
 
-        self.from_file = arg1
-        self.to_file = arg2
-        if self.to_file == "-":
-            self.to_file = None
+        if arg2 == "-":
+            arg2 = None
 
-    def getSynopsis(self):
-        return "%s get VDRIVE_FILE LOCAL_FILE" % (os.path.basename(sys.argv[0]),)
+        self.from_file = argv_to_unicode(arg1)
+        self.to_file   = None if arg2 is None else argv_to_abspath(arg2)
 
-    longdesc = """Retrieve a file from the virtual drive and write it to the
-    local filesystem. If LOCAL_FILE is omitted or '-', the contents of the file
-    will be written to stdout."""
+    synopsis = "[options] REMOTE_FILE LOCAL_FILE"
 
-class PutOptions(VDriveOptions):
+    description = """
+    Retrieve a file from the grid and write it to the local filesystem. If
+    LOCAL_FILE is omitted or '-', the contents of the file will be written to
+    stdout."""
+
+    description_unwrapped = """
+    Examples:
+     % tahoe get FOO |less            # write to stdout
+     % tahoe get tahoe:FOO |less      # same
+     % tahoe get FOO bar              # write to local file
+     % tahoe get tahoe:FOO bar        # same
+    """
+
+class PutOptions(FilesystemOptions):
     optFlags = [
-        ("mutable", "m", "Create a mutable file instead of an immutable one."),
+        ("mutable", "m", "Create a mutable file instead of an immutable one (like --format=SDMF)"),
+        ]
+    optParameters = [
+        ("format", None, None, "Create a file with the given format: SDMF and MDMF for mutable, CHK (default) for immutable. (case-insensitive)"),
         ]
 
     def parseArgs(self, arg1=None, arg2=None):
-        # cat FILE > tahoe put           # create unlinked file from stdin
-        # cat FILE > tahoe put FOO       # create tahoe:FOO from stdin
-        # cat FILE > tahoe put tahoe:FOO # same
-        # tahoe put bar FOO              # copy local 'bar' to tahoe:FOO
-        # tahoe put bar tahoe:FOO        # same
-
-        if arg1 is not None and arg2 is not None:
-            self.from_file = arg1
-            self.to_file = arg2
-        elif arg1 is not None and arg2 is None:
-            self.from_file = None
-            self.to_file = arg1
-        else:
-            self.from_file = arg1
-            self.to_file = arg2
-        if self.from_file == "-":
-            self.from_file = None
+        # see Examples below
+
+        if arg1 == "-":
+            arg1 = None
+
+        self.from_file = None if arg1 is None else argv_to_abspath(arg1)
+        self.to_file   = None if arg2 is None else argv_to_unicode(arg2)
+
+        if self['format']:
+            if self['format'].upper() not in ("SDMF", "MDMF", "CHK"):
+                raise usage.UsageError("%s is an invalid format" % self['format'])
+
+    synopsis = "[options] LOCAL_FILE REMOTE_FILE"
+
+    description = """
+    Put a file into the grid, copying its contents from the local filesystem.
+    If REMOTE_FILE is missing, upload the file but do not link it into a
+    directory; also print the new filecap to stdout. If LOCAL_FILE is missing
+    or '-', data will be copied from stdin. REMOTE_FILE is assumed to start
+    with tahoe: unless otherwise specified.
+
+    If the destination file already exists and is mutable, it will be
+    modified in-place, whether or not --mutable is specified. (--mutable only
+    affects creation of new files.)
+    """
+
+    description_unwrapped = """
+    Examples:
+     % cat FILE | tahoe put                # create unlinked file from stdin
+     % cat FILE | tahoe put -              # same
+     % tahoe put bar                       # create unlinked file from local 'bar'
+     % cat FILE | tahoe put - FOO          # create tahoe:FOO from stdin
+     % tahoe put bar FOO                   # copy local 'bar' to tahoe:FOO
+     % tahoe put bar tahoe:FOO             # same
+     % tahoe put bar MUTABLE-FILE-WRITECAP # modify the mutable file in-place
+    """
+
+class CpOptions(FilesystemOptions):
+    optFlags = [
+        ("recursive", "r", "Copy source directory recursively."),
+        ("verbose", "v", "Be noisy about what is happening."),
+        ("caps-only", None,
+         "When copying to local files, write out filecaps instead of actual "
+         "data (only useful for debugging and tree-comparison purposes)."),
+        ]
+
+    def parseArgs(self, *args):
+        if len(args) < 2:
+            raise usage.UsageError("cp requires at least two arguments")
+        self.sources = map(argv_to_unicode, args[:-1])
+        self.destination = argv_to_unicode(args[-1])
+
+    synopsis = "[options] FROM.. TO"
+
+    description = """
+    Use 'tahoe cp' to copy files between a local filesystem and a Tahoe grid.
+    Any FROM/TO arguments that begin with an alias indicate Tahoe-side
+    files or non-file arguments. Directories will be copied recursively.
+    New Tahoe-side directories will be created when necessary. Assuming that
+    you have previously set up an alias 'home' with 'tahoe create-alias home',
+    here are some examples:
+
+     tahoe cp ~/foo.txt home:  # creates tahoe-side home:foo.txt
+
+     tahoe cp ~/foo.txt /tmp/bar.txt home:  # copies two files to home:
 
-    def getSynopsis(self):
-        return "%s put LOCAL_FILE VDRIVE_FILE" % (os.path.basename(sys.argv[0]),)
+     tahoe cp ~/Pictures home:stuff/my-pictures  # copies directory recursively
 
-    longdesc = """Put a file into the virtual drive (copying the file's
-    contents from the local filesystem). LOCAL_FILE is required to be a
-    local file (it can't be stdin)."""
+    You can also use a dircap as either FROM or TO target:
 
-class RmOptions(VDriveOptions):
+     tahoe cp URI:DIR2-RO:ixqhc4kdbjxc7o65xjnveoewym:5x6lwoxghrd5rxhwunzavft2qygfkt27oj3fbxlq4c6p45z5uneq/blog.html ./   # copy Zooko's wiki page to a local file
+
+    This command still has some limitations: symlinks and special files
+    (device nodes, named pipes) are not handled very well. Arguments should
+    not have trailing slashes (they are ignored for directory arguments, but
+    trigger errors for file arguments). When copying directories, it can be
+    unclear whether you mean to copy the contents of a source directory, or
+    the source directory itself (i.e. whether the output goes under the
+    target directory, or one directory lower). Tahoe's rule is that source
+    directories with names are referring to the directory as a whole, and
+    source directories without names (e.g. a raw dircap) are referring to the
+    contents.
+    """
+
+class UnlinkOptions(FilesystemOptions):
     def parseArgs(self, where):
-        self.where = where
+        self.where = argv_to_unicode(where)
+
+    synopsis = "[options] REMOTE_FILE"
+    description = "Remove a named file from its parent directory."
 
-    def getSynopsis(self):
-        return "%s rm VE_FILE" % (os.path.basename(sys.argv[0]),)
+class RmOptions(UnlinkOptions):
+    synopsis = "[options] REMOTE_FILE"
+    description = "Remove a named file from its parent directory."
 
-class MvOptions(VDriveOptions):
+class MvOptions(FilesystemOptions):
     def parseArgs(self, frompath, topath):
-        self.from_file = frompath
-        self.to_file = topath
+        self.from_file = argv_to_unicode(frompath)
+        self.to_file = argv_to_unicode(topath)
 
-    def getSynopsis(self):
-        return "%s mv FROM TO" % (os.path.basename(sys.argv[0]),)
+    synopsis = "[options] FROM TO"
 
-class WebopenOptions(VDriveOptions):
-    def parseArgs(self, vdrive_pathname=""):
-        self['vdrive_pathname'] = vdrive_pathname
+    description = """
+    Use 'tahoe mv' to move files that are already on the grid elsewhere on
+    the grid, e.g., 'tahoe mv alias:some_file alias:new_file'.
 
-    longdesc = """Opens a webbrowser to the contents of some portion of the virtual drive."""
+    If moving a remote file into a remote directory, you'll need to append a
+    '/' to the name of the remote directory, e.g., 'tahoe mv tahoe:file1
+    tahoe:dir/', not 'tahoe mv tahoe:file1 tahoe:dir'.
 
-class ReplOptions(usage.Options):
+    Note that it is not possible to use this command to move local files to
+    the grid -- use 'tahoe cp' for that.
+    """
+
+class LnOptions(FilesystemOptions):
+    def parseArgs(self, frompath, topath):
+        self.from_file = argv_to_unicode(frompath)
+        self.to_file = argv_to_unicode(topath)
+
+    synopsis = "[options] FROM_LINK TO_LINK"
+
+    description = """
+    Use 'tahoe ln' to duplicate a link (directory entry) already on the grid
+    to elsewhere on the grid. For example 'tahoe ln alias:some_file
+    alias:new_file'. causes 'alias:new_file' to point to the same object that
+    'alias:some_file' points to.
+
+    (The argument order is the same as Unix ln. To remember the order, you
+    can think of this command as copying a link, rather than copying a file
+    as 'tahoe cp' does. Then the argument order is consistent with that of
+    'tahoe cp'.)
+
+    When linking a remote file into a remote directory, you'll need to append
+    a '/' to the name of the remote directory, e.g. 'tahoe ln tahoe:file1
+    tahoe:dir/' (which is shorthand for 'tahoe ln tahoe:file1
+    tahoe:dir/file1'). If you forget the '/', e.g. 'tahoe ln tahoe:file1
+    tahoe:dir', the 'ln' command will refuse to overwrite the 'tahoe:dir'
+    directory, and will exit with an error.
+
+    Note that it is not possible to use this command to create links between
+    local and remote files.
+    """
+
+class BackupConfigurationError(Exception):
     pass
 
+class BackupOptions(FilesystemOptions):
+    optFlags = [
+        ("verbose", "v", "Be noisy about what is happening."),
+        ("ignore-timestamps", None, "Do not use backupdb timestamps to decide whether a local file is unchanged."),
+        ]
+
+    vcs_patterns = ('CVS', 'RCS', 'SCCS', '.git', '.gitignore', '.cvsignore',
+                    '.svn', '.arch-ids','{arch}', '=RELEASE-ID',
+                    '=meta-update', '=update', '.bzr', '.bzrignore',
+                    '.bzrtags', '.hg', '.hgignore', '_darcs')
+
+    def __init__(self):
+        super(BackupOptions, self).__init__()
+        self['exclude'] = set()
+
+    def parseArgs(self, localdir, topath):
+        self.from_dir = argv_to_abspath(localdir)
+        self.to_dir = argv_to_unicode(topath)
+
+    synopsis = "[options] FROM ALIAS:TO"
+
+    def opt_exclude(self, pattern):
+        """Ignore files matching a glob pattern. You may give multiple
+        '--exclude' options."""
+        g = argv_to_unicode(pattern).strip()
+        if g:
+            exclude = self['exclude']
+            exclude.add(g)
+
+    def opt_exclude_from(self, filepath):
+        """Ignore file matching glob patterns listed in file, one per
+        line. The file is assumed to be in the argv encoding."""
+        abs_filepath = argv_to_abspath(filepath)
+        try:
+            exclude_file = file(abs_filepath)
+        except:
+            raise BackupConfigurationError('Error opening exclude file %s.' % quote_local_unicode_path(abs_filepath))
+        try:
+            for line in exclude_file:
+                self.opt_exclude(line)
+        finally:
+            exclude_file.close()
+
+    def opt_exclude_vcs(self):
+        """Exclude files and directories used by following version control
+        systems: CVS, RCS, SCCS, Git, SVN, Arch, Bazaar(bzr), Mercurial,
+        Darcs."""
+        for pattern in self.vcs_patterns:
+            self.opt_exclude(pattern)
+
+    def filter_listdir(self, listdir):
+        """Yields non-excluded childpaths in path."""
+        exclude = self['exclude']
+        exclude_regexps = [re.compile(fnmatch.translate(pat)) for pat in exclude]
+        for filename in listdir:
+            for regexp in exclude_regexps:
+                if regexp.match(filename):
+                    break
+            else:
+                yield filename
+
+    description = """
+    Add a versioned backup of the local FROM directory to a timestamped
+    subdirectory of the TO/Archives directory on the grid, sharing as many
+    files and directories as possible with earlier backups. Create TO/Latest
+    as a reference to the latest backup. Behaves somewhat like 'rsync -a
+    --link-dest=TO/Archives/(previous) FROM TO/Archives/(new); ln -sf
+    TO/Archives/(new) TO/Latest'."""
+
+class WebopenOptions(FilesystemOptions):
+    optFlags = [
+        ("info", "i", "Open the t=info page for the file"),
+        ]
+    def parseArgs(self, where=''):
+        self.where = argv_to_unicode(where)
+
+    synopsis = "[options] [ALIAS:PATH]"
+
+    description = """
+    Open a web browser to the contents of some file or
+    directory on the grid. When run without arguments, open the Welcome
+    page."""
+
+class ManifestOptions(FilesystemOptions):
+    optFlags = [
+        ("storage-index", "s", "Only print storage index strings, not pathname+cap."),
+        ("verify-cap", None, "Only print verifycap, not pathname+cap."),
+        ("repair-cap", None, "Only print repaircap, not pathname+cap."),
+        ("raw", "r", "Display raw JSON data instead of parsed."),
+        ]
+    def parseArgs(self, where=''):
+        self.where = argv_to_unicode(where)
+
+    synopsis = "[options] [ALIAS:PATH]"
+    description = """
+    Print a list of all files and directories reachable from the given
+    starting point."""
+
+class StatsOptions(FilesystemOptions):
+    optFlags = [
+        ("raw", "r", "Display raw JSON data instead of parsed"),
+        ]
+    def parseArgs(self, where=''):
+        self.where = argv_to_unicode(where)
+
+    synopsis = "[options] [ALIAS:PATH]"
+    description = """
+    Print statistics about of all files and directories reachable from the
+    given starting point."""
+
+class CheckOptions(FilesystemOptions):
+    optFlags = [
+        ("raw", None, "Display raw JSON data instead of parsed."),
+        ("verify", None, "Verify all hashes, instead of merely querying share presence."),
+        ("repair", None, "Automatically repair any problems found."),
+        ("add-lease", None, "Add/renew lease on all shares."),
+        ]
+    def parseArgs(self, *locations):
+        self.locations = map(argv_to_unicode, locations)
+
+    synopsis = "[options] [ALIAS:PATH]"
+    description = """
+    Check a single file or directory: count how many shares are available and
+    verify their hashes. Optionally repair the file if any problems were
+    found."""
+
+class DeepCheckOptions(FilesystemOptions):
+    optFlags = [
+        ("raw", None, "Display raw JSON data instead of parsed."),
+        ("verify", None, "Verify all hashes, instead of merely querying share presence."),
+        ("repair", None, "Automatically repair any problems found."),
+        ("add-lease", None, "Add/renew lease on all shares."),
+        ("verbose", "v", "Be noisy about what is happening."),
+        ]
+    def parseArgs(self, *locations):
+        self.locations = map(argv_to_unicode, locations)
+
+    synopsis = "[options] [ALIAS:PATH]"
+    description = """
+    Check all files and directories reachable from the given starting point
+    (which must be a directory), like 'tahoe check' but for multiple files.
+    Optionally repair any problems found."""
+
 subCommands = [
-    ["mkdir", None, MakeDirectoryOptions, "Create a new directory"],
-    ["add-alias", None, AddAliasOptions, "Add a new alias cap"],
-    ["ls", None, ListOptions, "List a directory"],
-    ["get", None, GetOptions, "Retrieve a file from the virtual drive."],
-    ["put", None, PutOptions, "Upload a file into the virtual drive."],
-    ["rm", None, RmOptions, "Unlink a file or directory in the virtual drive."],
-    ["mv", None, MvOptions, "Move a file within the virtual drive."],
-    ["webopen", None, WebopenOptions, "Open a webbrowser to the root_dir"],
-    ["repl", None, ReplOptions, "Open a python interpreter"],
+    ["mkdir", None, MakeDirectoryOptions, "Create a new directory."],
+    ["add-alias", None, AddAliasOptions, "Add a new alias cap."],
+    ["create-alias", None, CreateAliasOptions, "Create a new alias cap."],
+    ["list-aliases", None, ListAliasesOptions, "List all alias caps."],
+    ["ls", None, ListOptions, "List a directory."],
+    ["get", None, GetOptions, "Retrieve a file from the grid."],
+    ["put", None, PutOptions, "Upload a file into the grid."],
+    ["cp", None, CpOptions, "Copy one or more files or directories."],
+    ["unlink", None, UnlinkOptions, "Unlink a file or directory on the grid."],
+    ["rm", None, RmOptions, "Unlink a file or directory on the grid (same as unlink)."],
+    ["mv", None, MvOptions, "Move a file within the grid."],
+    ["ln", None, LnOptions, "Make an additional link to an existing file or directory."],
+    ["backup", None, BackupOptions, "Make target dir look like local dir."],
+    ["webopen", None, WebopenOptions, "Open a web browser to a grid file or directory."],
+    ["manifest", None, ManifestOptions, "List all files/directories in a subtree."],
+    ["stats", None, StatsOptions, "Print statistics about all files/directories in a subtree."],
+    ["check", None, CheckOptions, "Check a single file or directory."],
+    ["deep-check", None, DeepCheckOptions, "Check all files/directories reachable from a starting point."],
     ]
 
-def mkdir(config, stdout, stderr):
+def mkdir(options):
     from allmydata.scripts import tahoe_mkdir
-    rc = tahoe_mkdir.mkdir(config['node-url'],
-                           config.aliases,
-                           config.where,
-                           stdout, stderr)
+    rc = tahoe_mkdir.mkdir(options)
     return rc
 
-def add_alias(config, stdout, stderr):
+def add_alias(options):
     from allmydata.scripts import tahoe_add_alias
-    rc = tahoe_add_alias.add_alias(config['node-directory'],
-                                   config.alias,
-                                   config.cap,
-                                   stdout, stderr)
+    rc = tahoe_add_alias.add_alias(options)
     return rc
 
-def list(config, stdout, stderr):
+def create_alias(options):
+    from allmydata.scripts import tahoe_add_alias
+    rc = tahoe_add_alias.create_alias(options)
+    return rc
+
+def list_aliases(options):
+    from allmydata.scripts import tahoe_add_alias
+    rc = tahoe_add_alias.list_aliases(options)
+    return rc
+
+def list(options):
     from allmydata.scripts import tahoe_ls
-    rc = tahoe_ls.list(config['node-url'],
-                       config.aliases,
-                       config.where,
-                       config,
-                       stdout, stderr)
+    rc = tahoe_ls.list(options)
     return rc
 
-def get(config, stdout, stderr):
+def get(options):
     from allmydata.scripts import tahoe_get
-    rc = tahoe_get.get(config['node-url'],
-                       config.aliases,
-                       config.from_file,
-                       config.to_file,
-                       stdout, stderr)
+    rc = tahoe_get.get(options)
     if rc == 0:
-        if config.to_file is None:
+        if options.to_file is None:
             # be quiet, since the file being written to stdout should be
             # proof enough that it worked, unless the user is unlucky
             # enough to have picked an empty file
             pass
         else:
-            print >>stderr, "%s retrieved and written to %s" % \
-                  (config.from_file, config.to_file)
+            print >>options.stderr, "%s retrieved and written to %s" % \
+                  (options.from_file, options.to_file)
     return rc
 
-def put(config, stdout, stderr, stdin=sys.stdin):
+def put(options):
     from allmydata.scripts import tahoe_put
-    if config['quiet']:
-        verbosity = 0
-    else:
-        verbosity = 2
-    rc = tahoe_put.put(config['node-url'],
-                       config.aliases,
-                       config.from_file,
-                       config.to_file,
-                       config['mutable'],
-                       verbosity,
-                       stdin, stdout, stderr)
+    rc = tahoe_put.put(options)
+    return rc
+
+def cp(options):
+    from allmydata.scripts import tahoe_cp
+    rc = tahoe_cp.copy(options)
+    return rc
+
+def unlink(options, command="unlink"):
+    from allmydata.scripts import tahoe_unlink
+    rc = tahoe_unlink.unlink(options, command=command)
     return rc
 
-def rm(config, stdout, stderr):
-    from allmydata.scripts import tahoe_rm
-    if config['quiet']:
-        verbosity = 0
-    else:
-        verbosity = 2
-    rc = tahoe_rm.rm(config['node-url'],
-                     config.aliases,
-                     config.where,
-                     verbosity,
-                     stdout, stderr)
+def rm(options):
+    return unlink(options, command="rm")
+
+def mv(options):
+    from allmydata.scripts import tahoe_mv
+    rc = tahoe_mv.mv(options, mode="move")
     return rc
 
-def mv(config, stdout, stderr):
+def ln(options):
     from allmydata.scripts import tahoe_mv
-    rc = tahoe_mv.mv(config['node-url'],
-                     config.aliases,
-                     config.from_file,
-                     config.to_file,
-                     stdout, stderr)
+    rc = tahoe_mv.mv(options, mode="link")
     return rc
 
-def webopen(config, stdout, stderr):
-    import urllib, webbrowser
-    nodeurl = config['node-url']
-    if nodeurl[-1] != "/":
-        nodeurl += "/"
-    url = nodeurl + "uri/%s/" % urllib.quote(config['dir-cap'])
-    if config['vdrive_pathname']:
-        url += urllib.quote(config['vdrive_pathname'])
-    webbrowser.open(url)
-    return 0
-
-def repl(config, stdout, stderr):
-    import code
-    return code.interact()
+def backup(options):
+    from allmydata.scripts import tahoe_backup
+    rc = tahoe_backup.backup(options)
+    return rc
+
+def webopen(options, opener=None):
+    from allmydata.scripts import tahoe_webopen
+    rc = tahoe_webopen.webopen(options, opener=opener)
+    return rc
+
+def manifest(options):
+    from allmydata.scripts import tahoe_manifest
+    rc = tahoe_manifest.manifest(options)
+    return rc
+
+def stats(options):
+    from allmydata.scripts import tahoe_manifest
+    rc = tahoe_manifest.stats(options)
+    return rc
+
+def check(options):
+    from allmydata.scripts import tahoe_check
+    rc = tahoe_check.check(options)
+    return rc
+
+def deepcheck(options):
+    from allmydata.scripts import tahoe_check
+    rc = tahoe_check.deepcheck(options)
+    return rc
 
 dispatch = {
     "mkdir": mkdir,
     "add-alias": add_alias,
+    "create-alias": create_alias,
+    "list-aliases": list_aliases,
     "ls": list,
     "get": get,
     "put": put,
+    "cp": cp,
+    "unlink": unlink,
     "rm": rm,
     "mv": mv,
+    "ln": ln,
+    "backup": backup,
     "webopen": webopen,
-    "repl": repl,
+    "manifest": manifest,
+    "stats": stats,
+    "check": check,
+    "deep-check": deepcheck,
     }
-