Merge branch 'feature/idfpy_hidden_commands' into 'master'

idf.py: add support for subcommands hidden from help

See merge request espressif/esp-idf!6646
This commit is contained in:
Angus Gratton 2019-11-15 12:41:43 +08:00
commit 83b468f707
3 changed files with 20 additions and 2 deletions

View file

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

View file

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

View file

@ -65,6 +65,18 @@ class TestExtensions(unittest.TestCase):
finally: finally:
os.remove(link_path) 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): class TestDependencyManagement(unittest.TestCase):
def test_dependencies(self): def test_dependencies(self):