فهرست منبع

idf.py: add support for subcommands hidden from help

Sergei Silnov 6 سال پیش
والد
کامیت
2dbad4fe7b
3فایلهای تغییر یافته به همراه20 افزوده شده و 2 حذف شده
  1. 3 1
      tools/idf.py
  2. 5 1
      tools/test_idf_py/test_idf_extensions/test_ext/test_extension.py
  3. 12 0
      tools/test_idf_py/test_idf_py.py

+ 3 - 1
tools/idf.py

@@ -195,11 +195,13 @@ def init_cli(verbose_output=None):
                      deprecated=False,
                      dependencies=None,
                      order_dependencies=None,
+                     hidden=False,
                      **kwargs):
             super(Action, self).__init__(name, **kwargs)
 
             self.name = self.name or self.callback.__name__
             self.deprecated = deprecated
+            self.hidden = hidden
 
             if aliases is None:
                 aliases = []
@@ -405,7 +407,7 @@ def init_cli(verbose_output=None):
                     self._actions[name].params.append(option)
 
         def list_commands(self, ctx):
-            return sorted(self._actions)
+            return sorted(filter(lambda name: not self._actions[name].hidden, self._actions))
 
         def get_command(self, ctx, name):
             return self._actions.get(self.commands_with_aliases.get(name))

+ 5 - 1
tools/test_idf_py/test_idf_extensions/test_ext/test_extension.py

@@ -20,5 +20,9 @@ def action_extensions(base_actions, project_path=os.getcwd()):
                 "callback": test_callback,
                 "help": "Help for test subcommand.",
             },
-        },
+            "hidden_one": {
+                "callback": test_callback,
+                "hidden": True
+            }
+        }
     }

+ 12 - 0
tools/test_idf_py/test_idf_py.py

@@ -65,6 +65,18 @@ class TestExtensions(unittest.TestCase):
         finally:
             os.remove(link_path)
 
+    def test_hidden_commands(self):
+        try:
+            os.symlink(extension_path, link_path)
+            os.environ["IDF_EXTRA_ACTIONS_PATH"] = ";".join([os.path.join(current_dir, 'extra_path')])
+            output = subprocess.check_output([sys.executable, idf_py_path, "--help"],
+                                             env=os.environ).decode('utf-8', 'ignore')
+            self.assertIn('test_subcommand', output)
+            self.assertNotIn('hidden_one', output)
+
+        finally:
+            os.remove(link_path)
+
 
 class TestDependencyManagement(unittest.TestCase):
     def test_dependencies(self):