Skip to content

Commit

Permalink
Merge pull request #43 from junghoon-vans/feature/support-pass-values…
Browse files Browse the repository at this point in the history
…-containing-equals-sign

feat: Support pass values containing equals sign
  • Loading branch information
junghoon-vans authored Dec 27, 2022
2 parents 5da2599 + d5ff7fe commit 84c4b69
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
16 changes: 2 additions & 14 deletions tests/utils/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def parser() -> Generator[Parser, None, None]:
'varst=variable to reStructuredText',
'version=0.2.0',
'release=v0.2.0',
'url=https://example.com?query=new-value',
])
yield parser

Expand All @@ -22,6 +23,7 @@ def test_parse_sub_pairs(parser: Parser):
'varst': 'variable to reStructuredText',
'version': '0.2.0',
'release': 'v0.2.0',
'url': 'https://example.com?query=new-value',
}


Expand All @@ -46,17 +48,3 @@ def test_parse_one_element(parser: Parser):
parser.parse(['key='])
with argparse_error():
parser.parse(['=value'])


def test_parse_more_than_two_element(parser: Parser):
with argparse_error():
parser.parse(['key=value=else'])


def test_parse_many_equals(parser: Parser):
with argparse_error():
parser.parse(['key==value'])
with argparse_error():
parser.parse(['key===value'])
with argparse_error():
parser.parse(['key====value'])
4 changes: 2 additions & 2 deletions varst/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _pattern_type(arg_value: str, pat=_VARIABLE_PATTERN) -> str:
argparse.ArgumentTypeError
"""
if not pat.fullmatch(arg_value):
if not pat.match(arg_value):
raise argparse.ArgumentTypeError(f"invalid pattern: {pat.pattern}")
return arg_value

Expand Down Expand Up @@ -107,7 +107,7 @@ def _parse_kv(variables: List[str]) -> Dict[str, str]:
result: Dict[str, str] = {}

for variable in variables:
kv = variable.split("=")
kv = variable.split("=", 1)
result[kv.pop()] = kv.pop()

return result

0 comments on commit 84c4b69

Please sign in to comment.