diff --git a/lbry/service/parser.py b/lbry/service/parser.py index f7f9561b3..a904c86f2 100644 --- a/lbry/service/parser.py +++ b/lbry/service/parser.py @@ -218,9 +218,8 @@ 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('--'): - lines[-1] = lines[-1] + ' ' + line.strip() - else: - lines.append(f"{' ' * len(left)} {line}") + raise Exception(f"Continuation line starts with -- on {method['cli']}: \"{line.strip()}\"") + 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 5507e3b60..7e5db9242 100644 --- a/tests/unit/service/test_parser.py +++ b/tests/unit/service/test_parser.py @@ -45,6 +45,9 @@ class FakeAPI: ) -> Paginated[Wallet]: # list of wallets """list command doc""" + def thing_save(self, **another_test_kwargs): + """save command doc""" + def thing_update(self, value1: str) -> Wallet: # updated wallet """update command doc""" @@ -89,11 +92,20 @@ class BadAPI(FakeAPI): class TestParser(TestCase): maxDiff = None - def test_parse_does_not_duplicate_arguments(self): + def test_parse_does_not_allow_duplicate_arguments(self): with self.assertRaises(Exception) as exc: parse_method(BadAPI.thing_search, get_expanders()) self.assertEqual(exc.exception.args[0], "Expander 'another_test' argument repeated: thing_search.") + def test_parse_does_not_allow_line_break_with_two_dashes(self): + # breaking with two dashes breaks docopt parsing + with self.assertRaises(Exception) as exc: + get_api_definitions(FakeAPI) + self.assertEqual( + exc.exception.args[0], + "Continuation line starts with -- on thing save: \"--angry [default: 3]\"" + ) + def test_parse_method(self): expanders = get_expanders() self.assertEqual( @@ -301,27 +313,3 @@ 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" - }""")