diff --git a/spec/options_spec.lua b/spec/options_spec.lua index 2cee54c..eaeeaab 100644 --- a/spec/options_spec.lua +++ b/spec/options_spec.lua @@ -17,6 +17,13 @@ describe("tests related to options", function() assert.same({server = "foo"}, args) end) + it("normalizes default target", function() + local parser = Parser() + parser:option("--from-server") + local args = parser:parse({"--from-server", "foo"}) + assert.same({from_server = "foo"}, args) + end) + it("handles non-standard charset", function() local parser = Parser() parser:option "/s" diff --git a/src/argparse.lua b/src/argparse.lua index 0f72156..0c531bd 100644 --- a/src/argparse.lua +++ b/src/argparse.lua @@ -783,7 +783,7 @@ function Parser:_parse(args, errhandler) end local type_ = option:_get_type() - targets[option] = option:_get_target() + targets[option] = option:_get_target():gsub("-", "_") if type_ == "counter" then result[targets[option]] = 0