[ctl] allow to specific instance name for instance commands in $CW_INSTANCE
Closes #17253994
--- a/cubicweb/cwctl.py Tue Nov 05 23:19:15 2019 +0100
+++ b/cubicweb/cwctl.py Wed Nov 06 12:52:50 2019 +0100
@@ -21,6 +21,7 @@
# *ctl module should limit the number of import to be imported as quickly as
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
# completion). So import locally in command helpers.
+import os
import sys
import traceback
from warnings import filterwarnings
@@ -107,7 +108,8 @@
arguments = '<instance>'
# enforce having one instance
- min_args = max_args = 1
+ min_args = 0
+ max_args = 1
options = (
("force",
@@ -142,7 +144,14 @@
"""run the <command>_method on each argument (a list of instance
identifiers)
"""
- appid = args[0]
+ if not args:
+ if "CW_INSTANCE" in os.environ:
+ appid = os.environ["CW_INSTANCE"]
+ else:
+ raise BadCommandUsage("Error: instance id is missing")
+ else:
+ appid = args[0]
+
cmdmeth = getattr(self, '%s_instance' % self.name)
traceback_ = None
--- a/doc/changes/3.27.rst Tue Nov 05 23:19:15 2019 +0100
+++ b/doc/changes/3.27.rst Wed Nov 06 12:52:50 2019 +0100
@@ -49,6 +49,9 @@
* add a new '-t/--toolbar' option the pyramid command to activate the pyramid debugtoolbar
+* allow to specify the instance id for any instance command using the
+ CW_INSTANCE global variable instead of or giving it as a cli argument
+
Backwards incompatible changes
------------------------------