diff --git a/tools/idf.py b/tools/idf.py index bc4a55610..2d8f5891f 100755 --- a/tools/idf.py +++ b/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)) diff --git a/tools/test_idf_py/test_idf_extensions/test_ext/test_extension.py b/tools/test_idf_py/test_idf_extensions/test_ext/test_extension.py index 089ee8623..9ec5bf155 100644 --- a/tools/test_idf_py/test_idf_extensions/test_ext/test_extension.py +++ b/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 + } + } } diff --git a/tools/test_idf_py/test_idf_py.py b/tools/test_idf_py/test_idf_py.py index 60cc49453..212fc9e59 100755 --- a/tools/test_idf_py/test_idf_py.py +++ b/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):