Skip to content

Commit

Permalink
fix(cli): Hack around cliargs quirk to handle "help" flag correctly (#…
Browse files Browse the repository at this point in the history
…732)

Co-authored-by: Caleb Maclennan <[email protected]>
  • Loading branch information
TheMagician23 and alerque authored Oct 25, 2024
1 parent a2c755b commit 94d0081
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions busted/modules/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ return function(options)
-- Parse the cli arguments
local cliArgs, cliErr = cli:parse(args)
if not cliArgs then
if cliErr:match("^Usage") then
return { help = true, helpText = cliErr }, nil
end

return nil, appName .. ': error: ' .. cliErr .. '; re-run with --help for usage.'
end

Expand Down
7 changes: 6 additions & 1 deletion busted/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ return function(options)
exit(1, forceExit)
end

if cliArgs.help then
io.stdout:write(cliArgs.helpText .. '\n')
exit(0, forceExit)
end

if cliArgs.version then
-- Return early if asked for the version
print(busted.version)
io.stdout:write(busted.version .. '\n')
exit(0, forceExit)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/cl_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('Tests the busted command-line options', function()

it('tests running with --help specified', function()
local success, _ = executeBusted('--help')
assert.is_false(success)
assert.is_true(success)
end)

it('tests running a non-compiling testfile', function()
Expand Down Expand Up @@ -353,7 +353,7 @@ describe('Test busted running standalone', function()

it('tests running with --help specified', function()
local success = executeLua('spec/cl_standalone.lua --help')
assert.is_false(success)
assert.is_true(success)
end)

it('tests running via stdin', function()
Expand Down

0 comments on commit 94d0081

Please sign in to comment.