From 95ff6333f87f0e4abdcb679a44abd2249108a542 Mon Sep 17 00:00:00 2001
From: Danijel Schorlemmer <ds@gfz-potsdam.de>
Date: Fri, 16 Sep 2022 09:36:17 +0200
Subject: [PATCH] Simplify command-line parsing

---
 exposureinitializer/exposureinitializer.py | 54 ++++++++--------------
 1 file changed, 18 insertions(+), 36 deletions(-)

diff --git a/exposureinitializer/exposureinitializer.py b/exposureinitializer/exposureinitializer.py
index ddd7272..6b53190 100644
--- a/exposureinitializer/exposureinitializer.py
+++ b/exposureinitializer/exposureinitializer.py
@@ -507,34 +507,22 @@ def command_line_interface():
 
     # Create the argument parser and prepare for subparsers
     parser = argparse.ArgumentParser(description="Exposure-Initializer")
-    subparsers = parser.add_subparsers(help="sub-command help", dest="command")
-
-    # Create the parser for the 'local' command
-    parser_local = subparsers.add_parser(
-        "local", help="Run initializer on a local SpatiaLite database"
-    )
-    parser_local.add_argument(
-        "-e",
-        "--exposure-database",
-        required=True,
-        type=str,
-        help="Filepath to the SpatiaLite exposure database",
-    )
-    parser_local.add_argument(
+    parser_shared = argparse.ArgumentParser(add_help=False)
+    parser_shared.add_argument(
         "-c",
         "--config-file",
         required=True,
         type=str,
         help="Filepath of the config file for accessing the Tiles database",
     )
-    parser_local.add_argument(
+    parser_shared.add_argument(
         "-m",
         "--exposure-model",
         required=True,
         type=str,
         help="Search pattern for exposure files",
     )
-    parser_local.add_argument(
+    parser_shared.add_argument(
         "-i",
         "--country-iso-code",
         required=True,
@@ -542,30 +530,24 @@ def command_line_interface():
         help="ISO 3166-1 alpha-3 code of the country",
     )
 
-    # Create the parser for the 'server' command
-    parser_server = subparsers.add_parser(
-        "server", help="Run initializer on a server-based PostGIS database"
-    )
-    parser_server.add_argument(
-        "-c",
-        "--config-file",
-        required=True,
-        type=str,
-        help="Filepath of the config file for accessing the Tiles database",
+    # Prepare for subparsers
+    subparsers = parser.add_subparsers(help="sub-command help", dest="command")
+    # Create the parser for the 'local' command
+    parser_local = subparsers.add_parser(
+        "local", help="Run initializer on a local SpatiaLite database", parents=[parser_shared]
     )
-    parser_server.add_argument(
-        "-m",
-        "--exposure-model",
+    parser_local.add_argument(
+        "-e",
+        "--exposure-database",
         required=True,
         type=str,
-        help="Search pattern for exposure files",
+        help="Filepath to the SpatiaLite exposure database",
     )
-    parser_server.add_argument(
-        "-i",
-        "--country-iso-code",
-        required=True,
-        type=str,
-        help="ISO 3166-1 alpha-3 code of the country",
+    # Create the parser for the 'server' command
+    subparsers.add_parser(
+        "server",
+        help="Run initializer on a server-based PostGIS database",
+        parents=[parser_shared],
     )
 
     # Read arguments from command line
-- 
GitLab