added info on recent additions to interface

This commit is contained in:
mpeterv
2014-01-23 20:17:03 +04:00
parent c763e19b40
commit ddcf1834f6
2 changed files with 53 additions and 31 deletions

View File

@@ -8,6 +8,31 @@ Not everything stated here is implemented.
Features:
* Declarative and usual interfaces.
Declarative:
```lua
parser:argument "input"
:description "Path to input file. "
:convert(io.open)
parser:option "-v" "--verbose"
:description "Sets logging level. "
:count "*"
```
Usual:
```lua
parser:argument("input", {
description = "Path to input file. ",
convert = io.open
})
parser:option("-v", "--verbose", {
description = "Sets logging level. ",
count = "*"
})
```
* Parses:
* Short options(e.g. `-q`);
* Combined short options(e.g. `-zx`);
@@ -21,14 +46,12 @@ Features:
Example:
```lua
parser:option "-p" "--pair" {
count = "*",
args = 2
}
parser:option "-p" "--pair"
:count "*"
:args(2)
parser:flag "-v" "--verbose" {
count = "*"
}
parser:flag "-v" "--verbose"
:count "*"
local args = parser:parse{"--pair", "Alice", "Bob", "-p", "Emma", "John", "-vvv"}
-- args = {
@@ -41,5 +64,5 @@ Features:
```
* Supports default values and automatic conversions for arguments.
* [___NYI___] Automatically generates error, help and usage 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.

View File

@@ -9,15 +9,13 @@ describe("tests related to usage message generation", function()
it("creates correct usage message for arguments", function()
local parser = argparse.parser "foo"
parser:argument "first"
parser:argument "second-and-third" {
args = 2
}
parser:argument "maybe-fourth" {
args = "?"
}
parser:argument "others" {
args = "*"
}
parser:argument "second-and-third"
:args "2"
parser:argument "maybe-fourth"
:args "?"
parser:argument "others"
:args "*"
assert.equal(
[=[Usage: foo <first> <second-and-third> <second-and-third> [<maybe-fourth>] [<others>] ...]=],
parser:prepare():get_usage()
@@ -27,11 +25,11 @@ describe("tests related to usage message generation", function()
it("creates correct usage message for options", function()
local parser = argparse.parser "foo"
parser:flag "-q" "--quiet"
parser:option "--from" {
count = 1,
target = "server"
}
parser:option "--from"
:count "1"
:target "server"
parser:option "--config"
assert.equal(
[=[Usage: foo [-q] --from <server> [--config <config>]]=],
parser:prepare():get_usage()
@@ -43,6 +41,7 @@ describe("tests related to usage message generation", function()
parser:flag "-q" "--quiet"
local run = parser:command "run"
run:option "--where"
assert.equal(
[=[Usage: foo [-q] [<command>] ...]=],
parser:prepare():get_usage()
@@ -51,10 +50,10 @@ describe("tests related to usage message generation", function()
describe("usage generation can be customized", function()
it("uses message provided by user", function()
local parser = argparse.parser "foo" {
usage = "Usage: obvious"
}
local parser = argparse.parser "foo"
:usage "Usage: obvious"
parser:flag "-q" "--quiet"
assert.equal(
[=[Usage: obvious]=],
parser:prepare():get_usage()
@@ -63,9 +62,9 @@ describe("tests related to usage message generation", function()
it("uses per-option message provided by user", function()
local parser = argparse.parser "foo"
parser:flag "-q" "--quiet" {
usage = "[-q | --quiet]"
}
parser:flag "-q" "--quiet"
:usage "[-q | --quiet]"
assert.equal(
[=[Usage: foo [-q | --quiet]]=],
parser:prepare():get_usage()
@@ -74,10 +73,10 @@ describe("tests related to usage message generation", function()
it("uses argnames provided by user", function()
local parser = argparse.parser "foo"
parser:argument "inputs" {
args = "1-2",
argname = "<input>"
}
parser:argument "inputs"
:args "1-2"
:argname "<input>"
assert.equal(
[=[Usage: foo <input> [<input>]]=],
parser:prepare():get_usage()