changeset 3282:e7e7be79fbcd

core (launcher): extra arguments can now be passed the service with `bg`, `fg` and `dbg`: - `dbg` is an alias for `debug` - extra arguments can be passed to the service, use `-- --help` to see them`
author Goffi <goffi@goffi.org>
date Mon, 25 May 2020 16:15:05 +0200 (2020-05-25)
parents a3639d6d9643
children 7b58b15bd121
files sat/core/launcher.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat/core/launcher.py	Mon May 25 15:50:01 2020 +0200
+++ b/sat/core/launcher.py	Mon May 25 16:15:05 2020 +0200
@@ -139,22 +139,27 @@
         parser = argparse.ArgumentParser(description=f"Launch {self.APP_NAME} backend")
         parser.set_defaults(cmd=self.cmd_background)
         subparsers = parser.add_subparsers()
+        extra_help = f"arguments to pass to {self.APP_NAME} service"
 
         bg_parser = subparsers.add_parser(
             'background',
             aliases=['bg'],
             help=f"run {self.APP_NAME} backend in background (as a daemon)")
+        bg_parser.add_argument('extra_args', nargs=argparse.REMAINDER, help=extra_help)
         bg_parser.set_defaults(cmd=self.cmd_background)
 
         fg_parser = subparsers.add_parser(
             'foreground',
             aliases=['fg'],
             help=f"run {self.APP_NAME} backend in foreground")
+        fg_parser.add_argument('extra_args', nargs=argparse.REMAINDER, help=extra_help)
         fg_parser.set_defaults(cmd=self.cmd_foreground)
 
         dbg_parser = subparsers.add_parser(
             'debug',
+            aliases=['dbg'],
             help=f"run {self.APP_NAME} backend in debug mode")
+        dbg_parser.add_argument('extra_args', nargs=argparse.REMAINDER, help=extra_help)
         dbg_parser.set_defaults(cmd=self.cmd_debug)
 
         stop_parser = subparsers.add_parser(
@@ -206,6 +211,12 @@
         if twistd_opts is not None:
             server_opts.extend(twistd_opts)
         server_opts.append(self.APP_NAME_FILE)
+        if args.extra_args:
+            try:
+                args.extra_args.remove('--')
+            except ValueError:
+                pass
+            server_opts.extend(args.extra_args)
         try:
             server_options.parseOptions(server_opts)
         except usage.error as ue: