summary refs log tree commit diff
path: root/synapse/config
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-07-01 17:55:26 +0100
committerErik Johnston <erik@matrix.org>2019-07-02 17:12:48 +0100
commit9f3c0a8556a82960c795b8dc41a4666e0adebfef (patch)
tree0121a0e5ca3c1ccd414f4b3cba404de44ec21018 /synapse/config
parentNewsfile (diff)
downloadsynapse-9f3c0a8556a82960c795b8dc41a4666e0adebfef.tar.xz
Add basic admin cmd app
Diffstat (limited to '')
-rw-r--r--synapse/config/_base.py48
1 files changed, 45 insertions, 3 deletions
diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index 965478d8d5..14d3f7c1fe 100644
--- a/synapse/config/_base.py
+++ b/synapse/config/_base.py
@@ -201,6 +201,26 @@ class Config(object):
 
         Returns: Config object.
         """
+        config_parser = cls.create_argument_parser(description)
+        obj, _ = cls.load_config_with_parser(config_parser, argv)
+
+        return obj
+
+    @classmethod
+    def create_argument_parser(cls, description):
+        """Create an ArgumentParser instance with all the config flags.
+
+        Doesn't support config-file-generation: used by the worker apps.
+
+        Used for workers where we want to add extra flags/subcommands.
+
+        Args:
+            description (str): App description
+
+        Returns:
+            ArgumentParser
+        """
+
         config_parser = argparse.ArgumentParser(description=description)
         config_parser.add_argument(
             "-c",
@@ -219,9 +239,31 @@ class Config(object):
             " Defaults to the directory containing the last config file",
         )
 
-        obj = cls()
+        # We can only invoke `add_arguments` on an actual object, but
+        # `add_arguments` should be side effect free so this is probably fine.
+        cls().invoke_all("add_arguments", config_parser)
 
-        obj.invoke_all("add_arguments", config_parser)
+        return config_parser
+
+    @classmethod
+    def load_config_with_parser(cls, config_parser, argv):
+        """Parse the commandline and config files with the given parser
+
+        Doesn't support config-file-generation: used by the worker apps.
+
+        Used for workers where we want to add extra flags/subcommands.
+
+        Args:
+            conifg_parser (ArgumentParser)
+            argv (list[str])
+
+        Returns:
+            tuple[HomeServerConfig, argparse.Namespace]: Returns the parsed
+            config object and the parsed argparse.Namespace object from
+            `config_parser.parse_args(..)`
+        """
+
+        obj = cls()
 
         config_args = config_parser.parse_args(argv)
 
@@ -244,7 +286,7 @@ class Config(object):
 
         obj.invoke_all("read_arguments", config_args)
 
-        return obj
+        return obj, config_args
 
     @classmethod
     def load_or_generate_config(cls, description, argv):