Make command required by default

This commit is contained in:
mpeterv
2014-02-23 16:27:23 +04:00
parent fc65c85a13
commit 7994dded7e
5 changed files with 7 additions and 6 deletions

View File

@@ -47,11 +47,11 @@ describe("tests related to commands", function()
local parser = Parser "name" local parser = Parser "name"
parser:command "install" parser:command "install"
assert.has_error(function() parser:parse{} end, "a command is required")
parser:require_command(false)
local args = parser:parse{} local args = parser:parse{}
assert.same({}, args) assert.same({}, args)
parser:require_command(true)
assert.has_error(function() parser:parse{} end, "a command is required")
end) end)
it("Detects wrong commands", function() it("Detects wrong commands", function()

View File

@@ -106,7 +106,7 @@ Sets verbosity level.
run:option "--where" run:option "--where"
assert.equal(table.concat({ assert.equal(table.concat({
"Usage: foo [-q] [-h] [<command>] ...", "Usage: foo [-q] [-h] <command> ...",
"", "",
"Options: ", "Options: ",
" -q, --quiet", " -q, --quiet",

View File

@@ -3,6 +3,7 @@ local Parser = require "argparse"
local parser = Parser "test" local parser = Parser "test"
:description "A testing program. " :description "A testing program. "
:require_command(false)
parser:argument "input" parser:argument "input"

View File

@@ -65,7 +65,7 @@ describe("tests related to usage message generation", function()
run:option "--where" run:option "--where"
assert.equal( assert.equal(
[=[Usage: foo [-q] [<command>] ...]=], [=[Usage: foo [-q] <command> ...]=],
parser:prepare():get_usage() parser:prepare():get_usage()
) )
end) end)

View File

@@ -48,7 +48,7 @@ local Parser = class {
_arguments = {}, _arguments = {},
_options = {}, _options = {},
_commands = {}, _commands = {},
_require_command = false, _require_command = true,
_add_help = true, _add_help = true,
_fields = { _fields = {
"name", "description", "require_command", "name", "description", "require_command",