diff options
| author | ruki <[email protected]> | 2026-08-01 08:53:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-08-01 08:53:30 +0800 |
| commit | 8d7a74306556a4c292c0345f1a9aa833116ebcec (patch) | |
| tree | 49b0b3ae14157a3f24193623d6adb69e282675e9 /xmake/plugins/plugin | |
| parent | f91724eb1d7f80e81772ad6f20b03b2a0cff8125 (diff) | |
improve tests
Diffstat (limited to 'xmake/plugins/plugin')
| -rw-r--r-- | xmake/plugins/plugin/main.lua | 26 | ||||
| -rw-r--r-- | xmake/plugins/plugin/xmake.lua | 12 |
2 files changed, 14 insertions, 24 deletions
diff --git a/xmake/plugins/plugin/main.lua b/xmake/plugins/plugin/main.lua index 48bae9cde..5158352c0 100644 --- a/xmake/plugins/plugin/main.lua +++ b/xmake/plugins/plugin/main.lua @@ -74,17 +74,17 @@ function _install_plugins_from_repo(name, reponame) raise("plugin(%s): not found in any repository! try ${bright}xrepo update-repo${clear} first.", name) end --- install a plugin from a local directory -function _install_from_local(dir) +-- install a single plugin from a source directory (as the given name, default to the directory name) +function _install_from_local(dir, name) assert(os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")), "plugin path(%s): ${bright}xmake.lua${clear} not found!", dir) - local name = path.filename(path.absolute(dir)) + name = name or path.filename(path.absolute(dir)) local dstdir = _get_plugindir(name) assert(not os.isdir(dstdir), "plugin(%s) already exists!", name) os.vcp(dir, dstdir) - cprint("${color.success}install ${bright}%s${clear} from ${bright}%s${clear} ok!", name, dir) + cprint("${color.success}install ${bright}%s${clear} ok!", name) end --- install a plugin from a git url or github shortcut +-- install a single plugin from a git url or github shortcut, e.g. https://github.com/xmake-io/hello-world function _install_from_git(url) local branch if url:startswith("github:") then @@ -95,9 +95,11 @@ function _install_from_git(url) end url = git.asgiturl(url) end + local name = (path.filename(url):gsub("%.git$", "")) local tmpdir = os.tmpfile() .. ".dir" git.clone(url, {verbose = option.get("verbose"), branch = branch, outputdir = tmpdir}) - _copy_plugins_from_dir(tmpdir) + os.tryrm(path.join(tmpdir, ".git")) + _install_from_local(tmpdir, name) os.tryrm(tmpdir) end @@ -131,18 +133,6 @@ function _install_one(name) _install_plugins_from_repo(name) end --- copy every plugin found under the cloned directory into the plugins directory -function _copy_plugins_from_dir(tmpdir) - for _, filepath in ipairs(os.files(path.join(tmpdir, "*", "xmake.lua"))) do - local srcdir = path.directory(filepath) - local name = path.filename(srcdir) - local dstdir = _get_plugindir(name) - assert(not os.isdir(dstdir), "plugin(%s) already exists!", name) - os.vcp(srcdir, dstdir) - cprint(" ${color.success}-> ${bright}%s${clear}", name) - end -end - -- install plugins function _install() local names = assert(option.get("plugins"), "please specify the plugins to be installed!") diff --git a/xmake/plugins/plugin/xmake.lua b/xmake/plugins/plugin/xmake.lua index 8da06a92e..4aab3daa4 100644 --- a/xmake/plugins/plugin/xmake.lua +++ b/xmake/plugins/plugin/xmake.lua @@ -31,13 +31,13 @@ task("plugin") {'c', "clear", "k", nil, "Clear all installed plugins."}, {nil, "plugins", "vs", nil, "The plugin paths, urls or names.", "e.g.", - " $ xmake plugin --install https://github.com/xmake-io/xmake-plugins", - " $ xmake plugin --install github:xmake-io/xmake-plugins", - " $ xmake plugin --install github:xmake-io/xmake-plugins#dev", + " $ xmake plugin --install https://github.com/myrepo/hello", + " $ xmake plugin --install github:myrepo/hello", + " $ xmake plugin --install github:myrepo/hello#dev", " $ xmake plugin --install /tmp/my-plugin", - " $ xmake plugin --install xmake-repo@hello-world", - " $ xmake plugin --install hello-world", - " $ xmake plugin --remove hello-world", + " $ xmake plugin --install xmake-repo@hello", + " $ xmake plugin --install hello", + " $ xmake plugin --remove hello", " $ xmake plugin --list"} } } |
