From 857317d5804cdda8c3f4fca949bcf97ed26d7c10 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 10 Oct 2017 16:22:47 +0100 Subject: [PATCH] sphinxext: Warn if namespace or command pattern invalid Calling the Sphinx extension with an invalid namespace or command pattern currently results in a silent failure. Correct this oversight by raising a warning, which will cause a build failure is 'warning-is-error' is enabled. Change-Id: I63d18c86931d752c3a680e84a69df53bc04e7dfd Signed-off-by: Stephen Finucane --- cliff/sphinxext.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cliff/sphinxext.py b/cliff/sphinxext.py index d8468b63..5ec34485 100644 --- a/cliff/sphinxext.py +++ b/cliff/sphinxext.py @@ -268,6 +268,15 @@ class AutoprogramCliffDirective(rst.Directive): if fnmatch.fnmatch(x, command_pattern)] else: commands = manager.commands.keys() + + if not commands: + msg = 'No commands found in the "{}" namespace' + if command_pattern: + msg += ' using the "{}" command name/pattern' + msg += ('. Are you sure this is correct and the application being ' + 'documented is installed?') + raise self.warning(msg.format(self.arguments[0], command_pattern)) + return dict((name, self._load_command(manager, name)) for name in commands)