minor refactoring

This commit is contained in:
mpeterv
2014-01-20 18:06:02 +04:00
parent 66ab7b1076
commit bb69e443de
2 changed files with 8 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ Features:
* Combined short options(e.g. `-zx`);
* Short options combined with arguments(e.g. `-I/usr/local/include`);
* Long options(e.g. `--quiet`);
* Long options with arguments(e.g. `--from there);
* Long options with arguments(e.g. `--from there`);
* GNU-style long options with arguments(e.g. `--from=there`).
* Supports named arguments consuming several arguments.
* Supports options and flags which can be invoked several times, consuming several arguments.

View File

@@ -40,13 +40,15 @@ local Parser = class {
options = {},
commands = {},
require_command = false,
fields = {"name", "description", "target", "require_command"}
fields = {
"name", "description", "target", "require_command"
}
}:include(Declarative)
local Command = Parser:extends {
__name = "Command",
aliases = {}
}:include(Declarative)
}
local Argument = class {
__name = "Argument",
@@ -58,10 +60,9 @@ local Argument = class {
}
}:include(Declarative)
local Option = class {
local Option = Argument:extends {
__name = "Option",
aliases = {},
args = 1,
count = "?",
overwrite = true,
fields = {
@@ -70,12 +71,12 @@ local Option = class {
"mincount", "maxcount", "default", "convert",
"overwrite"
}
}:include(Declarative)
}
local Flag = Option:extends {
__name = "Flag",
args = 0
}:include(Declarative)
}
function Parser:argument(...)
local argument = Argument:new(...)