mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
added another test for usage generation
This commit is contained in:
19
README.md
19
README.md
@@ -8,7 +8,7 @@ Not everything stated here is implemented.
|
|||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
|
||||||
* Declarative and usual interfaces.
|
* Declarative and classic interfaces.
|
||||||
|
|
||||||
Declarative:
|
Declarative:
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ Features:
|
|||||||
:count "*"
|
:count "*"
|
||||||
```
|
```
|
||||||
|
|
||||||
Usual:
|
Classic:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
parser:argument("input", {
|
parser:argument("input", {
|
||||||
@@ -66,3 +66,18 @@ Features:
|
|||||||
* Supports default values and automatic conversions for arguments.
|
* Supports default values and automatic conversions for arguments.
|
||||||
* Automatically generates error, usage and help(__NYI__) messages.
|
* Automatically generates error, usage and help(__NYI__) messages.
|
||||||
* Supports commands(e.g. in [git](http://git-scm.com/) CLI `add`, `commit`, `push`, etc. are commands). Each command has its own set of options and arguments.
|
* Supports commands(e.g. in [git](http://git-scm.com/) CLI `add`, `commit`, `push`, etc. are commands). Each command has its own set of options and arguments.
|
||||||
|
* Automatically generates tips on typos(__NYI__).
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
parser:option "-f" "--from"
|
||||||
|
parser:command "install"
|
||||||
|
|
||||||
|
parser:parse{"--form", "there"}
|
||||||
|
-- Error: unknown option --form
|
||||||
|
-- Did you mean --from?
|
||||||
|
|
||||||
|
parser:parse{"isntall"}
|
||||||
|
-- Error: unknown command isntall
|
||||||
|
-- Did you mean install?
|
||||||
|
@@ -48,6 +48,20 @@ describe("tests related to usage message generation", function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("creates correct usage message for subcommands", function()
|
||||||
|
local parser = argparse.parser "foo"
|
||||||
|
parser:flag "-q" "--quiet"
|
||||||
|
local run = parser:command "run"
|
||||||
|
run:option "--where"
|
||||||
|
|
||||||
|
parser:prepare()
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
[=[Usage: foo run [--where <where>]]=],
|
||||||
|
run:prepare():get_usage()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
describe("usage generation can be customized", function()
|
describe("usage generation can be customized", function()
|
||||||
it("uses message provided by user", function()
|
it("uses message provided by user", function()
|
||||||
local parser = argparse.parser "foo"
|
local parser = argparse.parser "foo"
|
||||||
|
Reference in New Issue
Block a user