mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Add hidden command and option aliases
Also auto-add an alias with dashes in place of underscores if an alias has an underscore.
This commit is contained in:
@@ -311,6 +311,24 @@ Commands:
|
||||
Usage: foo]], parser:get_help())
|
||||
end)
|
||||
|
||||
it("does not mention hidden option and command aliases", function()
|
||||
local parser = Parser "foo"
|
||||
parser:option "--server"
|
||||
:hidden_name "--from"
|
||||
parser:command "newname"
|
||||
:hidden_name "oldname"
|
||||
|
||||
assert.equal([[
|
||||
Usage: foo [-h] [--server <server>] <command> ...
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message and exit.
|
||||
--server <server>
|
||||
|
||||
Commands:
|
||||
newname]], parser:get_help())
|
||||
end)
|
||||
|
||||
it("supports grouping options", function()
|
||||
local parser = Parser "foo"
|
||||
:add_help(false)
|
||||
|
@@ -57,14 +57,14 @@ describe("tests related to options", function()
|
||||
assert.same({server = {"foo", "bar"}}, args)
|
||||
end)
|
||||
|
||||
it("handles short option correclty", function()
|
||||
it("handles short option correctly", function()
|
||||
local parser = Parser()
|
||||
parser:option "-s" "--server"
|
||||
local args = parser:parse({"-s", "foo"})
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
it("handles flag correclty", function()
|
||||
it("handles flag correctly", function()
|
||||
local parser = Parser()
|
||||
parser:flag "-q" "--quiet"
|
||||
local args = parser:parse({"--quiet"})
|
||||
@@ -73,7 +73,7 @@ describe("tests related to options", function()
|
||||
assert.same({}, args)
|
||||
end)
|
||||
|
||||
it("handles combined flags correclty", function()
|
||||
it("handles combined flags correctly", function()
|
||||
local parser = Parser()
|
||||
parser:flag "-q" "--quiet"
|
||||
parser:flag "-f" "--fast"
|
||||
@@ -88,7 +88,7 @@ describe("tests related to options", function()
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
it("handles flags combined with short option correclty", function()
|
||||
it("handles flags combined with short option correctly", function()
|
||||
local parser = Parser()
|
||||
parser:flag "-q" "--quiet"
|
||||
parser:option "-s" "--server"
|
||||
@@ -146,6 +146,14 @@ describe("tests related to options", function()
|
||||
assert.same({tail = {"foo", "--unrelated", "bar"}}, args)
|
||||
end)
|
||||
|
||||
it("handles hidden option aliases", function()
|
||||
local parser = Parser()
|
||||
parser:option "--server"
|
||||
:hidden_name "--from"
|
||||
local args = parser:parse{"--from", "foo"}
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
describe("Special chars set", function()
|
||||
it("handles windows-style options", function()
|
||||
local parser = Parser()
|
||||
|
Reference in New Issue
Block a user