summary refs log tree commit diff
path: root/synapse/app/admin_cmd.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-07-15 13:49:18 +0100
committerErik Johnston <erik@matrix.org>2019-07-15 14:09:35 +0100
commitc8f35d8d38c91b3493bd34363096a6e26756d8d7 (patch)
tree8b7660e666a9b39ab46f422a92389d7cad7968ca /synapse/app/admin_cmd.py
parentMove creation of ArgumentParser to caller (diff)
downloadsynapse-c8f35d8d38c91b3493bd34363096a6e26756d8d7.tar.xz
Use set_defaults(func=) style
Diffstat (limited to 'synapse/app/admin_cmd.py')
-rw-r--r--synapse/app/admin_cmd.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/synapse/app/admin_cmd.py b/synapse/app/admin_cmd.py
index c4d752593a..611a196e54 100644
--- a/synapse/app/admin_cmd.py
+++ b/synapse/app/admin_cmd.py
@@ -90,15 +90,17 @@ class AdminCmdReplicationHandler(ReplicationClientHandler):
 
 
 @defer.inlineCallbacks
-def export_data_command(hs, user_id, directory):
+def export_data_command(hs, args):
     """Export data for a user.
 
     Args:
-        user_id (str)
-        directory (str|None): Directory to write output to. Will create a temp
-            directory if not specified.
+        hs (HomeServer)
+        args (argparse.Namespace)
     """
 
+    user_id = args.user_id
+    directory = args.output_directory
+
     res = yield hs.get_handlers().admin_handler.exfiltrate_user_data(
         user_id, FileExfiltrationWriter(user_id, directory=directory)
     )
@@ -129,6 +131,7 @@ def start(config_options):
         help="The directory to store the exported data in. Must be emtpy. Defaults"
         " to creating a temp directory.",
     )
+    export_data_parser.set_defaults(func=export_data_command)
 
     try:
         config, args = HomeServerConfig.load_config_with_parser(parser, config_options)
@@ -173,12 +176,6 @@ def start(config_options):
 
     ss.setup()
 
-    if args.command == "export-data":
-        command = lambda: export_data_command(ss, args.user_id, args.output_directory)
-    else:
-        # This shouldn't happen.
-        raise ConfigError("Unknown admin command %s" % (args.command,))
-
     # We use task.react as the basic run command as it correctly handles tearing
     # down the reactor when the deferreds resolve and setting the return value.
     # We also make sure that `_base.start` gets run before we actually run the
@@ -188,7 +185,7 @@ def start(config_options):
     def run(_reactor):
         with LoggingContext("command"):
             yield _base.start(ss, [])
-            yield command()
+            yield args.func(ss, args)
 
     _base.start_worker_reactor(
         "synapse-admin-cmd", config, run_command=lambda: task.react(run)