4 local index =
#self.param_list_value[self.current]
5 self.param_list_value[self.current][index + 1] =
param
6 self.param_dict_value_alias[self.current][
param] = opt.alias
7 self.param_dict_value_default[self.current][
param] = opt and opt.default
8 self.param_dict_value_required[self.current][
param] = (opt and opt.required) ==
true
13 local index = #self.param_list_option_get[self.current]
14 self.param_list_option_get[self.current][index + 1] =
param
15 self.param_dict_option_get_alias[self.current][
param] = opt.alias
16 self.param_dict_option_get_default[self.current][
param] = opt and opt.default
17 self.param_dict_option_get_required[self.current][
param] = (opt and opt.required) ==
true
22 local index = #self.param_list_option_has[self.current]
23 self.param_list_option_has[self.current][index + 1] =
param
28 self.param_dict_option_get_required[cmd_name] = {}
29 self.param_dict_option_get_default[cmd_name] = {}
30 self.param_dict_option_get_alias[cmd_name] = {}
31 self.param_list_option_get[cmd_name] = {}
32 self.param_list_option_has[cmd_name] = {}
33 self.param_dict_value_required[cmd_name] = {}
34 self.param_dict_value_default[cmd_name] = {}
35 self.param_dict_value_alias[cmd_name] = {}
36 self.param_list_value[cmd_name] = {}
37 self.cmd_execution[cmd_name] = cmd_collection[cmd_name]
38 self.commands[#self.commands + 1] = cmd_name
39 self.current = cmd_name
43local function
run(self, host_args)
58 if not self.cmd_execution[
command] then
64 while index <= #self.param_list_option_has[
command]
do
73 while index <= #self.param_list_option_get[
command] and
command ~= self.error_usage
do
76 local alias = self.param_dict_option_get_alias[
command][
param]
77 local required = self.param_dict_option_get_required[
command][
param]
78 local default_value = self.param_dict_option_get_default[
command][
param]
79 if alias and (value or
''):sub(1, 1) == alias:sub(1, 1) then
80 value = self.param_dict_value_alias[
command][
param]:sub(2):gsub(
'{{'..
param..
'}}', value:sub(2))
82 if required and not value then
85 args[
param] = value or default_value
92 while index <= #self.param_list_value[
command] and
command ~= self.error_usage do
95 local alias = self.param_dict_value_alias[
command][
param]
96 local required = self.param_dict_value_required[
command][
param]
97 local default_value = self.param_dict_value_default[
command][
param]
98 if alias and (value or
''):sub(1, 1) == alias:sub(1, 1) then
99 value = self.param_dict_value_alias[
command][
param]:sub(2):gsub(
'{{'..
param..
'}}', value:sub(2))
101 if required and not value then
104 args[
param] = value or default_value
112 if self.cmd_execution[usage] then
119 if
command == self.error_usage then
120 args.params = self.param_list_value[args.
command]
121 args.option_get = self.param_list_option_get[args.
command]
122 args.option_has = self.param_list_option_has[args.
command]
125 return self.cmd_execution[
command](args)
128local function
from(host_args)
132 error_not_found = nil,
133 param_dict_option_get_required = {},
134 param_dict_option_get_default = {},
135 param_dict_option_get_alias = {},
136 param_list_option_get = {},
137 param_list_option_has = {},
138 param_dict_value_required = {},
139 param_dict_value_default = {},
140 param_dict_value_alias = {},
141 param_list_value = {},
147 cmd.add_next_value = function(
param, opt)
151 cmd.add_option_get = function(
param, opt)
155 cmd.add_option_has = function(
param, opt)
159 cmd.add_subcommand = function(cmd_name, cmd_collection)
163 cmd.add_help_subcommand = function(cmd_name, cmd_collection)
168 cmd.add_error_cmd_usage = function(cmd_name, cmd_collection)
169 cmd.error_usage = cmd_name
173 cmd.add_error_cmd_not_found = function(cmd_name, cmd_collection)
174 cmd.error_not_found = cmd_name
179 return
run(cmd, host_args)
local function run(self, host_args)
local function from(host_args)
local function add_subcommand(self, cmd_name, cmd_collection)
local function add_next_value(self, param, opt)
local function add_option_has(self, param)
local function add_option_get(self, param, opt)
local function current(game, application)
local function require(std, game, application)
local function param(self, name, value)