Skip to content

Commit

Permalink
Merge branch 'tickets/DM-27685' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
n8pease committed Dec 14, 2020
2 parents 391f7c2 + d5ee831 commit 91d8f7d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
5 changes: 5 additions & 0 deletions python/lsst/daf/butler/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ def addArgumentHelp(doc, helpText):
doc = doc.split("\f")[0]

doclines = doc.splitlines()
# The function's docstring may span multiple lines, so combine the
# docstring from all the first lines until a blank line is encountered.
# (Lines after the first blank line will be argument help.)
while len(doclines) > 1 and doclines[1]:
doclines[0] = " ".join((doclines[0], doclines.pop(1).strip()))
doclines.insert(1, helpText)
doclines.insert(1, "\n")
doc = "\n".join(doclines)
Expand Down
39 changes: 27 additions & 12 deletions tests/test_cliUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,36 @@

class ArgumentHelpGeneratorTestCase(unittest.TestCase):

@staticmethod
@click.command()
# Use custom help in the arguments so that any changes to default help text
# do not break this test unnecessarily.
@repo_argument(help="repo help text")
@directory_argument(help="directory help text")
def cli():
"""The cli help message."""
pass
def testHelp(self):
@click.command()
# Use custom help in the arguments so that any changes to default help
# text do not break this test unnecessarily.
@repo_argument(help="repo help text")
@directory_argument(help="directory help text")
def cli():
"""The cli help message."""
pass

def test_help(self):
self.runTest(cli)

def testHelpWrapped(self):
@click.command()
# Use custom help in the arguments so that any changes to default help
# text do not break this test unnecessarily.
@repo_argument(help="repo help text")
@directory_argument(help="directory help text")
def cli():
"""The cli
help
message."""
pass
self.runTest(cli)

def runTest(self, cli):
"""Tests `utils.addArgumentHelp` and its use in repo_argument and
directory_argument; verifies that the argument help gets added to the
command fucntion help, and that it's added in the correct order. See
addArgumentHelp for more details."""
runner = LogCliRunner()
result = runner.invoke(ArgumentHelpGeneratorTestCase.cli, ["--help"])
expected = """Usage: cli [OPTIONS] REPO DIRECTORY
The cli help message.
Expand All @@ -70,6 +83,8 @@ def test_help(self):
Options:
--help Show this message and exit.
"""
runner = LogCliRunner()
result = runner.invoke(cli, ["--help"])
self.assertIn(expected, result.output)


Expand Down

0 comments on commit 91d8f7d

Please sign in to comment.