idf.py: add support for subcommands hidden from help

This commit is contained in:
Sergei Silnov 2019-11-08 17:54:10 +01:00
parent 8b38d79dd3
commit 2dbad4fe7b
3 changed files with 20 additions and 2 deletions

View file

@ -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))

View file

@ -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
}
}
}

View file

@ -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):