diff options
| author | ruki <[email protected]> | 2017-09-21 23:27:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-21 14:42:01 +0800 |
| commit | 034185734b5bc91f8188c15c9e02b0ce8ebaa850 (patch) | |
| tree | 17788345197514d464006129d76a0d36f2addf35 /xmake/core/base | |
| parent | 253e814d11d2af31088a22401a28b4a6abef70e3 (diff) | |
improve option and add require option
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/option.lua | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index de87014ab..c8a613d0e 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -326,11 +326,7 @@ function option.init(menu) end -- value is "true" or "false", translate it - if type(value) == "string" then - if value == "true" or value == "yes" or value == "y" then value = true - elseif value == "false" or value == "no" or value == "n" then value = false - end - end + value = option.boolean(value) -- save option context.options[longname] = value @@ -592,11 +588,7 @@ function option.parse(argv, options) end -- value is "true" or "false", translate it - if type(value) == "string" then - if value == "true" or value == "yes" or value == "y" then value = true - elseif value == "false" or value == "no" or value == "n" then value = false - end - end + value = option.boolean(value) -- save option results[longname] = value @@ -712,7 +704,11 @@ function option.get(name) -- the options local options = option.options() if options then - return options[name] or option.default(name) + local value = options[name] + if value == nil then + value = option.default(name) + end + return value end end @@ -733,6 +729,17 @@ function option.set(name, value) options[name] = value end +-- get the boolean value +function option.boolean(value) + + if type(value) == "string" then + if value == "true" or value == "yes" or value == "y" then value = true + elseif value == "false" or value == "no" or value == "n" then value = false + end + end + return value +end + -- get the given default option value for the current task function option.default(name) |
