Skip to content

Commit ed258b5

Browse files
committed
Merge pull request #42 from o-lim/fix-usage
Update usage to print optional `--`
2 parents 98c0aa5 + 2ab34a8 commit ed258b5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/cliargs.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,15 @@ end
517517
function cli:print_usage(noprint)
518518
-- print the USAGE heading
519519
local msg = "Usage: " .. tostring(self.name)
520-
if self.optional[1] then
521-
msg = msg .. " [OPTIONS] "
520+
if #self.optional > 0 then
521+
msg = msg .. " [OPTIONS]"
522522
end
523-
if self.required[1] then
523+
if #self.required > 0 or self.optargument.maxcount > 0 then
524+
msg = msg .. " [--]"
525+
end
526+
if #self.required > 0 then
524527
for _,entry in ipairs(self.required) do
525-
msg = msg .. " " .. entry.key .. " "
528+
msg = msg .. " " .. entry.key
526529
end
527530
end
528531
if self.optargument.maxcount == 1 then
@@ -569,11 +572,11 @@ function cli:print_help(noprint)
569572
end
570573
end
571574

572-
if self.optargument.maxcount >0 then
575+
if self.optargument.maxcount > 0 then
573576
append(self.optargument.key, self.optargument.desc .. " (optional, default: " .. self.optargument.default .. ")")
574577
end
575578

576-
if self.optional[1] then
579+
if #self.optional > 0 then
577580
msg = msg .. "\nOPTIONS: \n"
578581

579582
for _,entry in ipairs(self.optional) do

0 commit comments

Comments
 (0)