From 741857e2c91b67b75e763b17ccdc6909bbc41709 Mon Sep 17 00:00:00 2001 From: Opportunity Date: Wed, 15 Jan 2020 17:57:26 +0800 Subject: fix complete --- scripts/register-completions.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1 index bae3281f8..f7e3e5da4 100644 --- a/scripts/register-completions.ps1 +++ b/scripts/register-completions.ps1 @@ -8,7 +8,7 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock { } $oldenv = $env:XMAKE_SKIP_HISTORY $env:XMAKE_SKIP_HISTORY = 1 - xmake lua private.utils.complete "0" "$complete" | ForEach-Object { + xmake lua private.utils.complete "0" "nospace" "$complete" | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } $env:XMAKE_SKIP_HISTORY = $oldenv -- cgit v1.3.1 From f005776c9b847595225f5e490639fcc4a159f845 Mon Sep 17 00:00:00 2001 From: Opportunity Date: Wed, 15 Jan 2020 18:07:08 +0800 Subject: fix complete --- scripts/get.sh | 4 ++-- scripts/register-completions.bash | 2 +- scripts/register-completions.ps1 | 2 +- scripts/register-completions.zsh | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/get.sh b/scripts/get.sh index c57f3bf4f..5f6bde3c2 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -170,7 +170,7 @@ if [[ "$SHELL" = */zsh ]]; then _xmake_zsh_complete() { - local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete 0 nospace "$words")") + local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete 0 nospace "$words")") reply=( "${(ps:\n:)completions}" ) } @@ -185,7 +185,7 @@ elif [[ "$SHELL" = */bash ]]; then local word=${COMP_WORDS[COMP_CWORD]} local completions - completions="$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)" + completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)" if [ $? -ne 0 ]; then completions="" fi diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash index 9d5865cd6..e45ce6489 100644 --- a/scripts/register-completions.bash +++ b/scripts/register-completions.bash @@ -5,7 +5,7 @@ _xmake_bash_complete() local word=${COMP_WORDS[COMP_CWORD]} local completions - completions="$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)" + completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)" if [ $? -ne 0 ]; then completions="" fi diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1 index f7e3e5da4..a9ecd7877 100644 --- a/scripts/register-completions.ps1 +++ b/scripts/register-completions.ps1 @@ -8,7 +8,7 @@ Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock { } $oldenv = $env:XMAKE_SKIP_HISTORY $env:XMAKE_SKIP_HISTORY = 1 - xmake lua private.utils.complete "0" "nospace" "$complete" | ForEach-Object { + xmake lua --root private.utils.complete "0" "nospace" "$complete" | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } $env:XMAKE_SKIP_HISTORY = $oldenv diff --git a/scripts/register-completions.zsh b/scripts/register-completions.zsh index 82f588d5f..5c16cf334 100644 --- a/scripts/register-completions.zsh +++ b/scripts/register-completions.zsh @@ -2,7 +2,7 @@ _xmake_zsh_complete() { - local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua private.utils.complete 0 nospace "$words")") + local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete 0 nospace "$words")") reply=( "${(ps:\n:)completions}" ) } -- cgit v1.3.1 From 19fef8183e250a49628a4281264753a7da1338dc Mon Sep 17 00:00:00 2001 From: Opportunity Date: Thu, 16 Jan 2020 20:20:39 +0800 Subject: fix complete --- scripts/get.sh | 2 +- scripts/register-completions.bash | 2 +- xmake/actions/build/xmake.lua | 29 ++++++------ xmake/actions/clean/xmake.lua | 5 +- xmake/actions/config/xmake.lua | 11 +++-- xmake/actions/install/xmake.lua | 15 +++--- xmake/actions/package/xmake.lua | 7 +-- xmake/actions/run/xmake.lua | 19 ++++---- xmake/actions/uninstall/xmake.lua | 23 ++++----- xmake/core/base/option.lua | 6 +-- xmake/core/base/text.lua | 13 +++-- xmake/modules/private/utils/complete.lua | 81 +++++++++++++++++++++++--------- 12 files changed, 131 insertions(+), 82 deletions(-) (limited to 'scripts') diff --git a/scripts/get.sh b/scripts/get.sh index 5f6bde3c2..a0d49c528 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -185,7 +185,7 @@ elif [[ "$SHELL" = */bash ]]; then local word=${COMP_WORDS[COMP_CWORD]} local completions - completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)" + completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "conf" "${COMP_LINE}" 2>/dev/null)" if [ $? -ne 0 ]; then completions="" fi diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash index e45ce6489..18df8a3b7 100644 --- a/scripts/register-completions.bash +++ b/scripts/register-completions.bash @@ -5,7 +5,7 @@ _xmake_bash_complete() local word=${COMP_WORDS[COMP_CWORD]} local completions - completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)" + completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "conf" "${COMP_LINE}" 2>/dev/null)" if [ $? -ne 0 ]; then completions="" fi diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua index aabc852bc..0eb4eb991 100644 --- a/xmake/actions/build/xmake.lua +++ b/xmake/actions/build/xmake.lua @@ -38,24 +38,25 @@ task("build") -- options , options = { - {'b', "build", "k", nil, "Build target. This is default building mode and optional." } - , {'r', "rebuild", "k", nil, "Rebuild the target." } - , {'a', "all", "k", nil, "Build all targets." } + {'b', "build", "k", nil , "Build target. This is default building mode and optional." } + , {'r', "rebuild", "k", nil , "Rebuild the target." } + , {'a', "all", "k", nil , "Build all targets." } , {} - , {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)), - "Specifies the number of jobs to build simultaneously." } - , {'w', "warning", "k", false, "Enable the warnings output." } - , {'t', "try", "k", false, "Try building project using third-party buildsystem." } - , {nil, "files", "kv", nil, "Build the given source files.", - "e.g. ", - " - xmake --files=src/main.c", - " - xmake --files='src/*.c' [target]", - " - xmake --files='src/**c|excluded_file.c'", - " - xmake --files='src/main.c" .. path.envsep() .. "src/test.c'" } + , {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)), + "Specifies the number of jobs to build simultaneously." } + , {'w', "warning", "k", false , "Enable the warnings output." } + , {'t', "try", "k", false , "Try building project using third-party buildsystem." } + , {nil, "files", "kv", nil , "Build the given source files.", + "e.g. ", + " - xmake --files=src/main.c", + " - xmake --files='src/*.c' [target]", + " - xmake --files='src/**c|excluded_file.c'", + " - xmake --files='src/main.c" .. path.envsep() .. "src/test.c'" } , {} - , {nil, "target", "v", nil, "The target name. It will build all default targets if this parameter is not specified." } + , {nil, "target", "v", nil , "The target name. It will build all default targets if this parameter is not specified." + , values = function () return table.keys(import("core.project.project").targets()) end } } } diff --git a/xmake/actions/clean/xmake.lua b/xmake/actions/clean/xmake.lua index a275d75e9..1b088c181 100644 --- a/xmake/actions/clean/xmake.lua +++ b/xmake/actions/clean/xmake.lua @@ -41,10 +41,11 @@ task("clean") -- options , options = { - {'a', "all", "k", nil, "Clean all auto-generated files by xmake." } + {'a', "all", "k", nil , "Clean all auto-generated files by xmake." } , {} - , {nil, "target", "v", nil, "The target name. It will clean all default targets if this parameter is not specified." } + , {nil, "target", "v", nil , "The target name. It will clean all default targets if this parameter is not specified." + , values = function () return table.keys(import("core.project.project").targets()) end } } } diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index e83e960da..8f1f1d06e 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -130,13 +130,14 @@ task("config") end , {category = "Other Configuration"} - , {nil, "debugger", "kv", "auto", "The Debugger" } - , {nil, "ccache", "kv", true, "Enable or disable the c/c++ compiler cache." - , " --ccache=[y|n]" } - , {'o', "buildir", "kv", "build", "Set the build directory." } + , {nil, "debugger", "kv", "auto" , "The Debugger" } + , {nil, "ccache", "kv", true , "Enable or disable the c/c++ compiler cache." + , " --ccache=[y|n]" } + , {'o', "buildir", "kv", "build" , "Set the build directory." } , {} - , {nil, "target", "v", nil, "Configure for the given target." } + , {nil, "target", "v", nil , "Configure for the given target." + , values = function () return table.keys(import("core.project.project").targets()) end } } } diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua index 38f013114..4aad1a62f 100644 --- a/xmake/actions/install/xmake.lua +++ b/xmake/actions/install/xmake.lua @@ -41,15 +41,16 @@ task("install") -- options , options = { - {'o', "installdir", "kv", nil, "Set the install directory.", - "e.g.", - " $ xmake install -o /usr/local", - "or $ DESTDIR=/usr/local xmake install", - "or $ INSTALLDIR=/usr/local xmake install" } - , {'a', "all", "k", nil, "Install all targets." } + {'o', "installdir", "kv", nil , "Set the install directory.", + "e.g.", + " $ xmake install -o /usr/local", + "or $ DESTDIR=/usr/local xmake install", + "or $ INSTALLDIR=/usr/local xmake install" } + , {'a', "all", "k", nil , "Install all targets." } , { } - , {nil, "target", "v", nil, "The target name. It will install all default targets if this parameter is not specified." } + , {nil, "target", "v", nil , "The target name. It will install all default targets if this parameter is not specified." + , values = function () return table.keys(import("core.project.project").targets()) end } } } diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 2a9ad1e53..d50562ad0 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -41,10 +41,11 @@ task("package") -- options , options = { - {'o', "outputdir", "kv", nil, "Set the output directory." } - , {'a', "all", "k", nil, "Package all targets." } + {'o', "outputdir", "kv", nil , "Set the output directory." } + , {'a', "all", "k", nil , "Package all targets." } , {} - , {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified." } + , {nil, "target", "v", nil , "The target name. It will package all default targets if this parameter is not specified." + , values = function () return table.keys(import("core.project.project").targets()) end } } } diff --git a/xmake/actions/run/xmake.lua b/xmake/actions/run/xmake.lua index eb4666d1b..6daf6f328 100644 --- a/xmake/actions/run/xmake.lua +++ b/xmake/actions/run/xmake.lua @@ -41,15 +41,16 @@ task("run") -- options , options = { - {'d', "debug", "k", nil, "Run and debug the given target." } - , {'a', "all", "k", nil, "Run all targets." } - , {'w', "workdir", "kv", nil, "Work directory of running targets, default is folder of targetfile", - "e.g.", - " --workdir=.", - " --workdir=`pwd`" } - , {} - , {nil, "target", "v", nil, "The target name. It will run all default targets if this parameter is not specified." } - , {nil, "arguments", "vs", nil, "The target arguments" } + {'d', "debug", "k", nil , "Run and debug the given target." } + , {'a', "all", "k", nil , "Run all targets." } + , {'w', "workdir", "kv", nil , "Work directory of running targets, default is folder of targetfile", + "e.g.", + " --workdir=.", + " --workdir=`pwd`" } + , {} + , {nil, "target", "v", nil , "The target name. It will run all default targets if this parameter is not specified." + , values = function () return table.keys(import("core.project.project").targets()) end } + , {nil, "arguments", "vs", nil , "The target arguments" } } } diff --git a/xmake/actions/uninstall/xmake.lua b/xmake/actions/uninstall/xmake.lua index c4672fad5..511b61e9e 100644 --- a/xmake/actions/uninstall/xmake.lua +++ b/xmake/actions/uninstall/xmake.lua @@ -41,17 +41,18 @@ task("uninstall") -- options , options = { - {nil, "installdir", "kv", nil, "Set the install directory.", - "e.g.", - " $ xmake uninstall -o /usr/local", - "or $ DESTDIR=/usr/local xmake uninstall", - "or $ INSTALLDIR=/usr/local xmake uninstall" } - , {'p', "prefix", "kv", nil, "Set the prefix directory.", - "e.g.", - " $ xmake uninstall --prefix=local", - "or $ PREFIX=local xmake uninstall" } - , { } - , {nil, "target", "v", nil, "The target name. It will uninstall all default targets if this parameter is not specified." } + {nil, "installdir", "kv", nil , "Set the install directory.", + "e.g.", + " $ xmake uninstall -o /usr/local", + "or $ DESTDIR=/usr/local xmake uninstall", + "or $ INSTALLDIR=/usr/local xmake uninstall" } + , {'p', "prefix", "kv", nil , "Set the prefix directory.", + "e.g.", + " $ xmake uninstall --prefix=local", + "or $ PREFIX=local xmake uninstall" } + , { } + , {nil, "target", "v", nil , "The target name. It will uninstall all default targets if this parameter is not specified." + , values = function () return table.keys(import("core.project.project").targets()) end } } } diff --git a/xmake/core/base/option.lua b/xmake/core/base/option.lua index 6a99a1cb9..c16b400e8 100644 --- a/xmake/core/base/option.lua +++ b/xmake/core/base/option.lua @@ -804,11 +804,11 @@ function option.show_options(options, taskname) end -- append values - local values = opt.values + local values, ok = opt.values if type(values) == "function" then - values = values() + ok, values = pcall(values) end - if values then + if ok and values then for _, value in ipairs(table.wrap(values)) do table.insert(desp_strs, " - " .. tostring(value)) end diff --git a/xmake/core/base/text.lua b/xmake/core/base/text.lua index 965c1daa9..0583ce7c4 100644 --- a/xmake/core/base/text.lua +++ b/xmake/core/base/text.lua @@ -148,8 +148,9 @@ end -- -- 2 numbers - min and max width (nil for not set, eg: {nil, 50}); -- -- a number - width, num is equivalent to {num, num}; -- -- nil - no limit, equivalent to {nil, nil} --- -- "auto" - use remain space of console, only one "auto" colunm is allowed +-- -- "auto" - use remain space of console, only one "auto" column is allowed -- align = {"l", "r", "c"} -- align mode for each column, "left", "center" or "right" +-- -- or use a string for the whole table -- sep = "${dim} | ", -- table colunm sepertor, default is " | ", use "" to hide -- } -- priority of style and align: cell > row > col @@ -159,7 +160,7 @@ function text.table(data, opt) assert(data) -- init options - opt = opt or { patch_reset = false, ignore_unknown = true } + opt = opt or { ignore_unknown = true } data.sep = data.sep or " | " opt.patch_reset = false @@ -216,6 +217,12 @@ function text.table(data, opt) data.sep = style .. data.sep .. "${reset}" end + local align = "l" + if type(data.align) == "string" then + align = data.align + data.align = {} + end + local sep = colors.translate(data.sep, opt) local sep_len = #colors.ignore(data.sep, opt) @@ -247,7 +254,7 @@ function text.table(data, opt) end -- load align - cols[i].align = (data.align[i] or "l"):sub(1, 1):lower() + cols[i].align = (data.align[i] or align):sub(1, 1):lower() -- load style cols[i].style = data.style[i] or style end diff --git a/xmake/modules/private/utils/complete.lua b/xmake/modules/private/utils/complete.lua index a1e8480df..70c54e056 100644 --- a/xmake/modules/private/utils/complete.lua +++ b/xmake/modules/private/utils/complete.lua @@ -23,6 +23,11 @@ import("core.base.option") import("core.base.task") local use_spaces = true +local raw_words = {} +local word = "" +local position = 0 +local has_space = false +local reenter = false function _print_candidate(is_complate, ...) local candidate = format(...) @@ -63,12 +68,25 @@ function _complete_option(options, segs, name) local current_options = try { function() - return option.raw_parse(segs, options, { populate_defaults = false }) + return option.raw_parse(segs, options, { populate_defaults = false, allow_unknown = true }) end } -- current options is invalid if not current_options then return end + -- current context is wrong + if not reenter and (current_options.file or current_options.project) then + local args = {"lua", "--root", "private.utils.complete", tostring(position), use_spaces and "reenter" or "nospace-reenter", table.unpack(raw_words) } + if current_options.file then + table.insert(args, 3, "--file=" .. current_options.file) + end + if current_options.project then + table.insert(args, 3, "--project=" .. current_options.project) + end + os.execv("xmake", args) + return + end + local state = 0 if name == "-" or name == "--" then name = "" @@ -112,28 +130,7 @@ function _complete_option(options, segs, name) end end -function main(position, config_use_spaces, ...) - local words = {...} - if config_use_spaces == "nospace" then - use_spaces = false - else - table.insert(words, 1, config_use_spaces) - end - - local word = table.concat(words, " ") or "" - position = tonumber(position) or 0 - local has_space = word:endswith(" ") or position > #word - word = word:trim() - - if is_host("windows") then - if word:lower():startswith("xmake.exe") then - word = "xmake" .. word:sub(#"xmake.exe" + 1) - end - end - - if word:lower():startswith("xmake ") then - word = word:sub(#"xmake " + 1) - end +function _complete() local tasks = {} local shortnames = {} @@ -167,4 +164,42 @@ function main(position, config_use_spaces, ...) if not has_space then segs[#segs] = nil end _complete_option(tasks[task_name].options, segs, incomplete_option) +end + +function main(pos, config, ...) + + raw_words = {...} + local words = {...} + + local is_config = false + if config:find("nospace", 1, true) then + use_spaces = false + is_config = true + end + if config:find("reenter", 1, true) then + reenter = true + is_config = true + end + + if not is_config then + table.insert(words, 1, config) + end + + word = table.concat(words, " ") or "" + position = tonumber(pos) or 0 + has_space = word:endswith(" ") or position > #word + word = word:trim() + + -- normailize word to "xmake ..." + if is_host("windows") then + if word:lower():startswith("xmake.exe") then + word = "xmake" .. word:sub(#"xmake.exe" + 1) + end + end + + if word:lower():startswith("xmake ") then + word = word:sub(#"xmake " + 1) + end + + _complete() end \ No newline at end of file -- cgit v1.3.1