cubicweb/cwctl.py
changeset 12754 22ece66dcd47
parent 12749 ff63319a1730
--- 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