mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
added info on recent additions to interface
This commit is contained in:
39
README.md
39
README.md
@@ -8,6 +8,31 @@ Not everything stated here is implemented.
|
|||||||
|
|
||||||
Features:
|
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:
|
* Parses:
|
||||||
* Short options(e.g. `-q`);
|
* Short options(e.g. `-q`);
|
||||||
* Combined short options(e.g. `-zx`);
|
* Combined short options(e.g. `-zx`);
|
||||||
@@ -21,14 +46,12 @@ Features:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
parser:option "-p" "--pair" {
|
parser:option "-p" "--pair"
|
||||||
count = "*",
|
:count "*"
|
||||||
args = 2
|
:args(2)
|
||||||
}
|
|
||||||
|
|
||||||
parser:flag "-v" "--verbose" {
|
parser:flag "-v" "--verbose"
|
||||||
count = "*"
|
:count "*"
|
||||||
}
|
|
||||||
|
|
||||||
local args = parser:parse{"--pair", "Alice", "Bob", "-p", "Emma", "John", "-vvv"}
|
local args = parser:parse{"--pair", "Alice", "Bob", "-p", "Emma", "John", "-vvv"}
|
||||||
-- args = {
|
-- args = {
|
||||||
@@ -41,5 +64,5 @@ Features:
|
|||||||
```
|
```
|
||||||
|
|
||||||
* Supports default values and automatic conversions for arguments.
|
* 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.
|
* 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.
|
||||||
|
@@ -9,15 +9,13 @@ describe("tests related to usage message generation", function()
|
|||||||
it("creates correct usage message for arguments", function()
|
it("creates correct usage message for arguments", function()
|
||||||
local parser = argparse.parser "foo"
|
local parser = argparse.parser "foo"
|
||||||
parser:argument "first"
|
parser:argument "first"
|
||||||
parser:argument "second-and-third" {
|
parser:argument "second-and-third"
|
||||||
args = 2
|
:args "2"
|
||||||
}
|
parser:argument "maybe-fourth"
|
||||||
parser:argument "maybe-fourth" {
|
:args "?"
|
||||||
args = "?"
|
parser:argument "others"
|
||||||
}
|
:args "*"
|
||||||
parser:argument "others" {
|
|
||||||
args = "*"
|
|
||||||
}
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
[=[Usage: foo <first> <second-and-third> <second-and-third> [<maybe-fourth>] [<others>] ...]=],
|
[=[Usage: foo <first> <second-and-third> <second-and-third> [<maybe-fourth>] [<others>] ...]=],
|
||||||
parser:prepare():get_usage()
|
parser:prepare():get_usage()
|
||||||
@@ -27,11 +25,11 @@ describe("tests related to usage message generation", function()
|
|||||||
it("creates correct usage message for options", function()
|
it("creates correct usage message for options", function()
|
||||||
local parser = argparse.parser "foo"
|
local parser = argparse.parser "foo"
|
||||||
parser:flag "-q" "--quiet"
|
parser:flag "-q" "--quiet"
|
||||||
parser:option "--from" {
|
parser:option "--from"
|
||||||
count = 1,
|
:count "1"
|
||||||
target = "server"
|
:target "server"
|
||||||
}
|
|
||||||
parser:option "--config"
|
parser:option "--config"
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
[=[Usage: foo [-q] --from <server> [--config <config>]]=],
|
[=[Usage: foo [-q] --from <server> [--config <config>]]=],
|
||||||
parser:prepare():get_usage()
|
parser:prepare():get_usage()
|
||||||
@@ -43,6 +41,7 @@ describe("tests related to usage message generation", function()
|
|||||||
parser:flag "-q" "--quiet"
|
parser:flag "-q" "--quiet"
|
||||||
local run = parser:command "run"
|
local run = parser:command "run"
|
||||||
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()
|
||||||
@@ -51,10 +50,10 @@ describe("tests related to usage message generation", function()
|
|||||||
|
|
||||||
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"
|
||||||
usage = "Usage: obvious"
|
:usage "Usage: obvious"
|
||||||
}
|
|
||||||
parser:flag "-q" "--quiet"
|
parser:flag "-q" "--quiet"
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
[=[Usage: obvious]=],
|
[=[Usage: obvious]=],
|
||||||
parser:prepare():get_usage()
|
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()
|
it("uses per-option message provided by user", function()
|
||||||
local parser = argparse.parser "foo"
|
local parser = argparse.parser "foo"
|
||||||
parser:flag "-q" "--quiet" {
|
parser:flag "-q" "--quiet"
|
||||||
usage = "[-q | --quiet]"
|
:usage "[-q | --quiet]"
|
||||||
}
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
[=[Usage: foo [-q | --quiet]]=],
|
[=[Usage: foo [-q | --quiet]]=],
|
||||||
parser:prepare():get_usage()
|
parser:prepare():get_usage()
|
||||||
@@ -74,10 +73,10 @@ describe("tests related to usage message generation", function()
|
|||||||
|
|
||||||
it("uses argnames provided by user", function()
|
it("uses argnames provided by user", function()
|
||||||
local parser = argparse.parser "foo"
|
local parser = argparse.parser "foo"
|
||||||
parser:argument "inputs" {
|
parser:argument "inputs"
|
||||||
args = "1-2",
|
:args "1-2"
|
||||||
argname = "<input>"
|
:argname "<input>"
|
||||||
}
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
[=[Usage: foo <input> [<input>]]=],
|
[=[Usage: foo <input> [<input>]]=],
|
||||||
parser:prepare():get_usage()
|
parser:prepare():get_usage()
|
||||||
|
Reference in New Issue
Block a user