From f25b5000fd7b85418d8ff85b070821748ef14f19 Mon Sep 17 00:00:00 2001 From: Daniel Pope Date: Fri, 31 May 2019 16:48:32 +0100 Subject: [PATCH] Do not register empty CLI groups from Blueprint (Fixes #3224) --- flask/blueprints.py | 3 +++ tests/test_cli.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/flask/blueprints.py b/flask/blueprints.py index 1e77be9e..30c864e0 100644 --- a/flask/blueprints.py +++ b/flask/blueprints.py @@ -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: diff --git a/tests/test_cli.py b/tests/test_cli.py index dba73a3f..25d6afd8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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