From 5e68213f01012513adae9c5858544fc6b51f2e7c Mon Sep 17 00:00:00 2001 From: Juan-Pablo Scaletti Date: Sun, 31 Mar 2024 13:26:26 -0500 Subject: [PATCH] Fix parser of positional args with --- pyproject.toml | 2 +- src/proper_cli/parser.py | 4 ++-- tests/test_parser.py | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 835a807..9bb4204 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "proper-cli" -version = "1.4" +version = "1.4.1" description = "Replace your HTML templates with Python server-Side components" authors = ["Juan-Pablo Scaletti "] license = "MIT" diff --git a/src/proper_cli/parser.py b/src/proper_cli/parser.py index e88d18d..335761b 100644 --- a/src/proper_cli/parser.py +++ b/src/proper_cli/parser.py @@ -26,8 +26,8 @@ def parse_args( # Split the "key=arg" arguments largs = [] for arg in cliargs: - if "=" in arg: - key, arg = arg.split("=") + if "-" == arg[0] and "=" in arg: + key, arg = arg.split("=", 1) largs.append(key) largs.append(arg) diff --git a/tests/test_parser.py b/tests/test_parser.py index cc191fa..5426a5c 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -2,8 +2,21 @@ def test_parse_args(): - result = parse_args(["abc", "xy", "-w=3", "--foo", "bar", "-narf=zort"]) - expected = (["abc", "xy"], {"foo": "bar", "w": "3", "narf": "zort"}) + result = parse_args([ + "abc", + "xy", + "meh:lorem=ipsum", + "-w=3", + "--foo", + "bar", + "-narf=zort", + "qwer=ty" + ]) + expected = ( + ["abc", "xy", "meh:lorem=ipsum"], + {"foo": "bar", "w": "3", "narf": ["zort", "qwer=ty"]}, + ) + print(result) assert result == expected