Skip to content

Commit

Permalink
feat: allow " escaped commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lukealvoeiro committed Sep 10, 2024
1 parent f46fb53 commit c26a5c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/goose/cli/prompt/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def command_itself(target_string: str) -> re.Pattern[str]:

def value_for_command(command_string: str) -> re.Pattern[str]:
escaped_string = re.escape(command_string)
return re.compile(rf"(?<=(?<!\S)\/{escaped_string})([^\s]*)")
return re.compile(rf"(?<=(?<!\S)\/{escaped_string})(?:(?:\"(.*?)(\"|$))|([^\s]*))")


class PromptLexer(Lexer):
Expand Down
20 changes: 11 additions & 9 deletions tests/cli/prompt/test_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,24 @@ def test_lex_document_ending_char_of_parameter_is_symbol():
assert actual_tokens == expected_tokens


def assert_pattern_matches(pattern, text, expected_group):
matches = pattern.search(text)
assert matches is not None
assert matches.group() == expected_group


def test_command_itself():
pattern = command_itself("file:")
matches = pattern.match("/file:example.txt")
assert matches is not None
assert matches.group(1) == "/file:"
assert_pattern_matches(pattern, "/file:example.txt", "/file:")


def test_value_for_command():
pattern = value_for_command("file:")
matches = pattern.search("/file:example.txt")
assert matches is not None
assert matches.group(1) == "example.txt"
assert_pattern_matches(pattern, "/file:example.txt", "example.txt")
assert_pattern_matches(pattern, '/file:"example space.txt"', '"example space.txt"')
assert_pattern_matches(pattern, '/file:"example.txt" some other string', '"example.txt"')


def test_completion_for_command():
pattern = completion_for_command("file:")
matches = pattern.search("/file:")
assert matches is not None
assert matches.group(1) == "file:"
assert_pattern_matches(pattern, "/file:", "/file:")

0 comments on commit c26a5c9

Please sign in to comment.