diff --git a/NEWS.md b/NEWS.md index 385745d..72241f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,9 @@ - don't crash when first unrecognized argument is also a handler name (boolean, file, finished, flag, etc...) + - don't hang when help text option table formats long option name + on its own line before indented description. + ## Noteworthy changes in release 1.1.1 (2016-02-07) [stable] diff --git a/lib/optparse/init.lua b/lib/optparse/init.lua index b7bab03..bcbb89b 100644 --- a/lib/optparse/init.lua +++ b/lib/optparse/init.lua @@ -648,7 +648,8 @@ local function _init (self, spec) -- Register option handlers according to the help text. for _, spec in ipairs (specs) do - local options, handler = {} + -- append a trailing space separator to match %s in patterns below + local options, spec, handler = {}, spec .. ' ' -- Loop around each '-' prefixed option on this line. while spec:sub (1, 1) == "-" do @@ -776,6 +777,8 @@ return setmetatable ({ -- -b a short option with no long option -- --long a long option with no short option -- --another-long a long option with internal hypen + -- --really-long-option-name + -- with description on following line -- -v, --verbose a combined short and long option -- -n, --dryrun, --dry-run several spellings of the same option -- -u, --name=USER require an argument diff --git a/specs/optparse_spec.yaml b/specs/optparse_spec.yaml index d48798e..da14219 100644 --- a/specs/optparse_spec.yaml +++ b/specs/optparse_spec.yaml @@ -32,6 +32,8 @@ specify optparse: --another-long a long option with internal hypen --true a Lua keyword as an option name --boolean an optparse handler as an option name + --really-long-option-name + with description on following line -v, --verbose a combined short and long option -n, --dryrun, --dry-run several spellings of the same option -u, --name=USER require an argument