diff options
| author | ruki <[email protected]> | 2015-06-04 11:06:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-04 11:06:33 +0800 |
| commit | e93e932433483348664804a0cc054b2c6af61a95 (patch) | |
| tree | 25bb8afda99c26c7082f5b2046e79702644405d4 /xmake/scripts/base/option.lua | |
| parent | 282c12b8f7b9b01a85844326c28f6bc3529aa088 (diff) | |
load platform from the project and global configure directory
Diffstat (limited to 'xmake/scripts/base/option.lua')
| -rw-r--r-- | xmake/scripts/base/option.lua | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua index df1fb54cb..cdf82adb5 100644 --- a/xmake/scripts/base/option.lua +++ b/xmake/scripts/base/option.lua @@ -320,6 +320,88 @@ function option.init(argv, menu) return true end +-- find the value of a given name from the arguments +-- only for kv mode and need not check it using menu +-- +function option.find(argv, name, shortname) + + -- check + assert(argv and name) + + -- parse _ARGV to _OPTIONS + local _iter, _s, _k = ipairs(argv) + while true do + + -- the idx and arg + local idx, arg = _iter(_s, _k) + + -- end? + _k = idx + if idx == nil then break end + + -- parse key and value + local key, value + local i = arg:find("=", 1, true) + + -- key=value? + if i then + key = arg:sub(1, i - 1) + value = arg:sub(i + 1) + -- only key? + else + key = arg + value = true + end + + -- --key? + local prefix = 0 + if key:startswith("--") then + key = key:sub(3) + prefix = 2 + -- -k? + elseif key:startswith("-") then + key = key:sub(2) + prefix = 1 + end + + -- check key + if prefix and #key == 0 then + -- failed + return + end + + -- --key=value or -k value or -k? + if prefix ~= 0 then + + -- -k value? continue to get the value + if prefix == 1 then + + -- get the next idx and arg + idx, arg = _iter(_s, _k) + + -- exists value? + _k = idx + if idx == nil or arg:startswith("-") then + -- failed + return + end + + -- get value + value = arg + end + + -- ok? + if key == name or (shortname and key == shortname) then + return value + end + + -- action? skip it + elseif idx == 1 then + -- value? + else return end + end +end + -- print the menu function option.print_menu(action) |
