mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Make command required by default
This commit is contained in:
@@ -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()
|
||||||
|
@@ -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",
|
||||||
|
@@ -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"
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
|
@@ -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",
|
||||||
|
Reference in New Issue
Block a user