Do not register empty CLI groups from Blueprint

(Fixes #3224)
This commit is contained in:
Daniel Pope 2019-05-31 16:48:32 +01:00
parent 14e9291380
commit f25b5000fd
2 changed files with 12 additions and 0 deletions

View file

@ -218,6 +218,9 @@ class Blueprint(_PackageBoundObject):
cli_resolved_group = options.get("cli_group", self.cli_group)
if not self.cli.commands:
return
if cli_resolved_group is None:
app.cli.commands.update(self.cli.commands)
elif cli_resolved_group is _sentinel:

View file

@ -652,3 +652,12 @@ def test_cli_blueprints(app):
result = app_runner.invoke(args=["late_registration", "late"])
assert "late_result" in result.output
def test_cli_empty(app):
"""If a Blueprint's CLI group is empty, do not register it."""
bp = Blueprint("blue", __name__, cli_group="blue")
app.register_blueprint(bp)
result = app.test_cli_runner().invoke(args=["blue", "--help"])
assert result.exit_code == 2, "Unexpected success:\n\n" + result.output