diff --git a/lbry/service/parser.py b/lbry/service/parser.py index 9f30db0d0..5b8247e03 100644 --- a/lbry/service/parser.py +++ b/lbry/service/parser.py @@ -218,11 +218,9 @@ def generate_options(method, indent) -> List[str]: # dont break on -- or docopt will parse as a new option for line_number, line in enumerate(wrapped): if line.strip().startswith('--'): - wrapped[line_number-1] += ' ' + line.strip() - wrapped[line_number] = '' - continue - for line in wrapped: - lines.append(f"{' '*len(left)} {line}") + lines[-1] = lines[-1] + ' ' + line.strip() + else: + lines.append(f"{' ' * len(left)} {line}") options.extend(lines) return options diff --git a/tests/unit/service/test_parser.py b/tests/unit/service/test_parser.py index e75d45302..50268542f 100644 --- a/tests/unit/service/test_parser.py +++ b/tests/unit/service/test_parser.py @@ -13,7 +13,12 @@ def test_kwargs(somevalue=1): @expander -def another_test_kwargs(somevalue=2, repeated=3): +def another_test_kwargs( + somevalue=1, + repeated=2, + bad_description=3, # using linebreaks makes docopt very very --angry + angry=4 +): pass @@ -45,8 +50,15 @@ class FakeAPI: def thing_search( self, - **test_and_another_test_kwargs): - """search command doc""" + query='a', + **test_and_another_test_kwargs) -> Wallet: + """ + search command doc + + Usage: + thing search [--query=] + {kwargs} + """ def thing_delete(self, value1: str, **tx_and_pagination_kwargs) -> Wallet: # deleted thing """ @@ -287,3 +299,27 @@ class TestGenerator(TestCase): (str) cheese foo bar""") ) + + def test_parse_does_not_break_with_two_dashes(self): + # breaking with two dashes breaks docopt parsing + definitions = get_api_definitions(FakeAPI) + self.assertEqual(definitions['commands']['thing_search']['help'], """search command doc + +Usage: + thing search [--query=] + [--somevalue=] [--repeated=] + [--bad_description=] [--angry=] + +Options: + --query= : (str) [default: 'a'] + --somevalue= : (int) [default: 1] + --repeated= : (int) [default: 2] + --bad_description= : (int) using linebreaks makes docopt very very --angry [default: 3] + --angry= : (int) [default: 4] + +Returns: + (Wallet) + { + "id": "wallet_id", + "name": "optional wallet name" + }""")