mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-10-02 07:02:29 +00:00
Added help message generation; Improved optional arguments handling.
This commit is contained in:
@@ -15,6 +15,14 @@ describe("tests related to positional arguments", function()
|
||||
assert.same({foo = "bar"}, args)
|
||||
end)
|
||||
|
||||
it("handles optional argument correctly", function()
|
||||
local parser = argparse.parser()
|
||||
parser:argument "foo"
|
||||
:args "?"
|
||||
local args = parser:parse({"bar"})
|
||||
assert.same({foo = "bar"}, args)
|
||||
end)
|
||||
|
||||
it("handles several arguments correctly", function()
|
||||
local parser = argparse.parser()
|
||||
parser:argument "foo1"
|
||||
@@ -86,6 +94,7 @@ describe("tests related to positional arguments", function()
|
||||
|
||||
it("handles sudden option correctly", function()
|
||||
local parser = argparse.parser()
|
||||
:add_help(false)
|
||||
parser:argument "foo"
|
||||
|
||||
assert.has_error(function() parser:parse{"-q"} end, "unknown option '-q'")
|
||||
|
@@ -13,6 +13,7 @@ describe("tests related to commands", function()
|
||||
|
||||
it("switches context properly", function()
|
||||
local parser = argparse.parser "name"
|
||||
:add_help(false)
|
||||
local install = parser:command "install"
|
||||
install:flag "-q" "--quiet"
|
||||
|
||||
|
@@ -185,6 +185,7 @@ describe("tests related to options", function()
|
||||
|
||||
it("handles unknown options correctly", function()
|
||||
local parser = argparse.parser()
|
||||
:add_help(false)
|
||||
assert.has_error(function() parser:parse{"--server"} end, "unknown option '--server'")
|
||||
assert.has_error(function() parser:parse{"--server=localhost"} end, "unknown option '--server'")
|
||||
assert.has_error(function() parser:parse{"-s"} end, "unknown option '-s'")
|
||||
|
@@ -3,11 +3,13 @@ local argparse = require "argparse"
|
||||
describe("tests related to usage message generation", function()
|
||||
it("creates correct usage message for empty parser", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
assert.equal(parser:prepare():get_usage(), "Usage: foo")
|
||||
end)
|
||||
|
||||
it("creates correct usage message for arguments", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
parser:argument "first"
|
||||
parser:argument "second-and-third"
|
||||
:args "2"
|
||||
@@ -24,6 +26,7 @@ describe("tests related to usage message generation", function()
|
||||
|
||||
it("creates correct usage message for options", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
parser:flag "-q" "--quiet"
|
||||
parser:option "--from"
|
||||
:count "1"
|
||||
@@ -38,6 +41,7 @@ describe("tests related to usage message generation", function()
|
||||
|
||||
it("creates correct usage message for commands", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
parser:flag "-q" "--quiet"
|
||||
local run = parser:command "run"
|
||||
run:option "--where"
|
||||
@@ -50,8 +54,10 @@ describe("tests related to usage message generation", function()
|
||||
|
||||
it("creates correct usage message for subcommands", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
parser:flag "-q" "--quiet"
|
||||
local run = parser:command "run"
|
||||
:add_help(false)
|
||||
run:option "--where"
|
||||
|
||||
parser:prepare()
|
||||
@@ -66,6 +72,7 @@ describe("tests related to usage message generation", function()
|
||||
it("uses message provided by user", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:usage "Usage: obvious"
|
||||
:add_help(false)
|
||||
parser:flag "-q" "--quiet"
|
||||
|
||||
assert.equal(
|
||||
@@ -76,6 +83,7 @@ describe("tests related to usage message generation", function()
|
||||
|
||||
it("uses per-option message provided by user", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
parser:flag "-q" "--quiet"
|
||||
:usage "[-q | --quiet]"
|
||||
|
||||
@@ -87,6 +95,7 @@ describe("tests related to usage message generation", function()
|
||||
|
||||
it("uses argnames provided by user", function()
|
||||
local parser = argparse.parser "foo"
|
||||
:add_help(false)
|
||||
parser:argument "inputs"
|
||||
:args "1-2"
|
||||
:argname "<input>"
|
||||
|
Reference in New Issue
Block a user