Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack around cliargs to provide "help" flag #732

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading