changeset 1364:df40708c4c76

server: renamed `--dev_mode` to `--dev-mode` and set it as a flag: good practice is to use a dash instead of underscode for CLI arguments. This options is actually a flag, no need to specify the value.
author Goffi <goffi@goffi.org>
date Fri, 20 Nov 2020 17:53:01 +0100
parents c3dac1e11341
children 10517a8698ca
files libervia/server/server.py libervia/server/tasks/manager.py twisted/plugins/libervia_server.py
diffstat 3 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/server.py	Sun Nov 15 16:59:55 2020 +0100
+++ b/libervia/server/server.py	Fri Nov 20 17:53:01 2020 +0100
@@ -1052,7 +1052,7 @@
         log.info(f"Libervia v{self.full_version}")
 
         # settings
-        if self.options['dev_mode']:
+        if self.options['dev-mode']:
             log.info(_("Developer mode activated"))
         self.media_dir = await self.bridgeCall("getConfig", "", "media_dir")
         self.local_dir = await self.bridgeCall("getConfig", "", "local_dir")
@@ -1083,7 +1083,7 @@
         self.sat_root = default_root = LiberviaRootResource(
             host=self, host_name='', site_name='',
             site_path=default_site_path, path=root_path)
-        if self.options['dev_mode']:
+        if self.options['dev-mode']:
             self.files_watcher.watchDir(
                 default_site_path, auto_add=True, recursive=True,
                 callback=LiberviaPage.onFileChange, site_root=self.sat_root,
@@ -1129,7 +1129,7 @@
 
                 existing_vhosts[encoded_site_name] = res
 
-                if self.options['dev_mode']:
+                if self.options['dev-mode']:
                     self.files_watcher.watchDir(
                         site_path, auto_add=True, recursive=True,
                         callback=LiberviaPage.onFileChange, site_root=res,
--- a/libervia/server/tasks/manager.py	Sun Nov 15 16:59:55 2020 +0100
+++ b/libervia/server/tasks/manager.py	Fri Nov 20 17:53:01 2020 +0100
@@ -127,7 +127,7 @@
 
         self.tasks[task_name] = task
         self.validateData(task)
-        if self.host.options['dev_mode']:
+        if self.host.options['dev-mode']:
             dirs = task.WATCH_DIRS or []
             for dir_ in dirs:
                 self.host.files_watcher.watchDir(
--- a/twisted/plugins/libervia_server.py	Sun Nov 15 16:59:55 2020 +0100
+++ b/twisted/plugins/libervia_server.py	Fri Nov 20 17:53:01 2020 +0100
@@ -131,8 +131,6 @@
                        ['base_url_ext', '', '',
                         _('The external URL to use as base URL').encode('utf-8'),
                         coerceUnicode],
-                       ['dev_mode', 'D', False, _('Developer mode, automatically reload '
-                        'modified pages').encode('utf-8'), coerceBool],
                       ]
 # Options which are in sat.conf only
 OPT_PARAMETERS_CFG = [
@@ -145,6 +143,12 @@
     ["mr_handlers_json", None, None, None],
 ]
 
+# Flags are in command line only
+OPT_FLAGS = [
+    ['dev-mode', 'D', _('Developer mode, automatically reload modified pages')],
+]
+
+
 
 def initialise(options):
     """Method to initialise global modules"""
@@ -166,6 +170,7 @@
 class Options(usage.Options):
     # optArgs is not really useful in our case, we need more than a flag
     optParameters = OPT_PARAMETERS_BOTH
+    optFlags = OPT_FLAGS
 
     def __init__(self):
         """Read SàT configuration file in order to overwrite the hard-coded default values