Skip to content

Commit

Permalink
fix(app) parse values that contain = or :
Browse files Browse the repository at this point in the history
replaces #370
  • Loading branch information
Tieske committed Jan 29, 2021
1 parent c2ff76d commit fb790bc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ see [CONTRIBUTING.md](CONTRIBUTING.md#release-instructions-for-a-new-version) fo
[#366](https://github.com/lunarmodules/Penlight/pull/366)
- feat: deprecation functionality `utils.raise_deprecation`
[#361](https://github.com/lunarmodules/Penlight/pull/361)
- feat: `utils.splitv` now takes same args as `split`
[#373](https://github.com/lunarmodules/Penlight/pull/373)
- fix: `dir.rmtree` failed to remove symlinks to directories
[#365](https://github.com/lunarmodules/Penlight/pull/365)
- fix: `pretty.write` could error out on failing metamethods (Lua 5.3+)
[#368](https://github.com/lunarmodules/Penlight/pull/368)

- fix: `app.parse` now correctly parses values containing '=' or ':'
[#373](https://github.com/lunarmodules/Penlight/pull/373)

## 1.9.2 (2020-09-27)

Expand Down
2 changes: 1 addition & 1 deletion lua/pl/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function app.parse_args (args,flags_with_values, flags_valid)
i = i + 1
else
-- a value can also be indicated with = or :
local var,val = utils.splitv (v,'[=:]')
local var,val = utils.splitv (v,'[=:]', false, 2)
var = var or v
val = val or true
if not is_long then
Expand Down
18 changes: 18 additions & 0 deletions tests/test-app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ do -- app.parse_args
asserteq(s, {})


-- flag_with_values missing value at end
local args = utils.split("-a -b")
local t,s = app.parse_args(args, { "b" })
asserteq(t, nil)
asserteq(s, "no value for 'b'")


-- error on an unknown flag
local args = utils.split("-a -b value -c")
local t,s = app.parse_args(args, { b = true }, { "b", "c" })
Expand All @@ -195,6 +202,17 @@ do -- app.parse_args
asserteq(s, {})


-- correctly parsed values, spaces, :, =, and multiple : or =
local args = utils.split("-a value -b value:one=two -c=value2:2")
local t,s = app.parse_args(args, { "a", "b", "c" })
asserteq(t, {
["a"] = "value",
["b"] = "value:one=two",
["c"] = "value2:2",
})
asserteq(s, {})


-- many values, duplicates, and parameters mixed
local args = utils.split(
"-a -b -cde --long1 --ff:ffvalue --gg=ggvalue -h:hvalue -i=ivalue " ..
Expand Down

0 comments on commit fb790bc

Please sign in to comment.