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`); * Combined short options(e.g. `-zx`);
* Short options combined with arguments(e.g. `-I/usr/local/include`); * Short options combined with arguments(e.g. `-I/usr/local/include`);
* Long options(e.g. `--quiet`); * 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`). * GNU-style long options with arguments(e.g. `--from=there`).
* Supports named arguments consuming several arguments. * Supports named arguments consuming several arguments.
* Supports options and flags which can be invoked several times, 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 = {}, options = {},
commands = {}, commands = {},
require_command = false, require_command = false,
fields = {"name", "description", "target", "require_command"} fields = {
"name", "description", "target", "require_command"
}
}:include(Declarative) }:include(Declarative)
local Command = Parser:extends { local Command = Parser:extends {
__name = "Command", __name = "Command",
aliases = {} aliases = {}
}:include(Declarative) }
local Argument = class { local Argument = class {
__name = "Argument", __name = "Argument",
@@ -58,10 +60,9 @@ local Argument = class {
} }
}:include(Declarative) }:include(Declarative)
local Option = class { local Option = Argument:extends {
__name = "Option", __name = "Option",
aliases = {}, aliases = {},
args = 1,
count = "?", count = "?",
overwrite = true, overwrite = true,
fields = { fields = {
@@ -70,12 +71,12 @@ local Option = class {
"mincount", "maxcount", "default", "convert", "mincount", "maxcount", "default", "convert",
"overwrite" "overwrite"
} }
}:include(Declarative) }
local Flag = Option:extends { local Flag = Option:extends {
__name = "Flag", __name = "Flag",
args = 0 args = 0
}:include(Declarative) }
function Parser:argument(...) function Parser:argument(...)
local argument = Argument:new(...) local argument = Argument:new(...)