diff options
| author | ruki <[email protected]> | 2020-10-24 20:24:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-10-24 20:24:59 +0800 |
| commit | fbe8fb9653040630b9e340e2dda44e80bcc0166d (patch) | |
| tree | e709f3760f631cb8474baa16c616db7a3964b0e8 | |
| parent | f60432d41958034846b50488ab7d061f80bef78b (diff) | |
rm all/update repo
| -rw-r--r-- | xmake/modules/private/xrepo/action/list-repo.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/rm-repo.lua | 31 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/update-repo.lua | 76 | ||||
| -rw-r--r-- | xmake/plugins/repo/main.lua | 6 |
4 files changed, 109 insertions, 6 deletions
diff --git a/xmake/modules/private/xrepo/action/list-repo.lua b/xmake/modules/private/xrepo/action/list-repo.lua index 6087f2443..ec9b908a0 100644 --- a/xmake/modules/private/xrepo/action/list-repo.lua +++ b/xmake/modules/private/xrepo/action/list-repo.lua @@ -72,5 +72,5 @@ end -- main entry function main(menu) - list_repository(name) + list_repository() end diff --git a/xmake/modules/private/xrepo/action/rm-repo.lua b/xmake/modules/private/xrepo/action/rm-repo.lua index c1fec99ae..2d2c2c779 100644 --- a/xmake/modules/private/xrepo/action/rm-repo.lua +++ b/xmake/modules/private/xrepo/action/rm-repo.lua @@ -30,14 +30,15 @@ function menu_options() -- menu options local options = { - {nil, "name", "v", nil, "The repository name."} + {nil, "all", "k", nil, "Remove all added repositories."}, + {nil, "name", "v", nil, "The repository name."} } -- show menu options local function show_options() -- show usage - cprint("${bright}Usage: $${clear cyan}xrepo rm-repo [options] name") + cprint("${bright}Usage: $${clear cyan}xrepo rm-repo [options] [name]") -- show description print("") @@ -74,11 +75,37 @@ function remove_repository(name) os.vexecv("xmake", repo_argv) end +-- clear repository +function clear_repository() + + -- enter working project directory + local workdir = path.join(os.tmpdir(), "xrepo", "working") + if not os.isdir(workdir) then + os.mkdir(workdir) + os.cd(workdir) + os.vrunv("xmake", {"create", "-P", "."}) + else + os.cd(workdir) + end + + -- clear all + local repo_argv = {"repo", "--clear", "--global"} + if option.get("verbose") then + table.insert(repo_argv, "-v") + end + if option.get("diagnosis") then + table.insert(repo_argv, "-D") + end + os.vexecv("xmake", repo_argv) +end + -- main entry function main(menu) local name = option.get("name") if name then remove_repository(name) + elseif option.get("all") then + clear_repository() else raise("please specify the repository name to be removed.") end diff --git a/xmake/modules/private/xrepo/action/update-repo.lua b/xmake/modules/private/xrepo/action/update-repo.lua new file mode 100644 index 000000000..4fcb460db --- /dev/null +++ b/xmake/modules/private/xrepo/action/update-repo.lua @@ -0,0 +1,76 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file update-repo.lua +-- + +-- imports +import("core.base.option") + +-- get menu options +function menu_options() + + -- description + local description = "update all local repositories from remote." + + -- menu options + local options = {} + + -- show menu options + local function show_options() + + -- show usage + cprint("${bright}Usage: $${clear cyan}xrepo update-repo [options]") + + -- show description + print("") + print(description) + + -- show options + option.show_options(options, "update-repo") + end + return options, show_options, description +end + +-- update repository +function update_repository() + + -- enter working project directory + local workdir = path.join(os.tmpdir(), "xrepo", "working") + if not os.isdir(workdir) then + os.mkdir(workdir) + os.cd(workdir) + os.vrunv("xmake", {"create", "-P", "."}) + else + os.cd(workdir) + end + + -- update it + local repo_argv = {"repo", "--update"} + if option.get("verbose") then + table.insert(repo_argv, "-v") + end + if option.get("diagnosis") then + table.insert(repo_argv, "-D") + end + os.vexecv("xmake", repo_argv) +end + +-- main entry +function main(menu) + update_repository() +end diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua index 2e870a867..e1fb3d2b2 100644 --- a/xmake/plugins/repo/main.lua +++ b/xmake/plugins/repo/main.lua @@ -160,11 +160,11 @@ function _clear(is_global) end -- list all repositories -function _list() +function _list(is_global) -- list all repositories local count = 0 - for _, position in ipairs(option.get("global") and "global" or {"local", "global"}) do + for _, position in ipairs(is_global and "global" or {"local", "global"}) do -- trace print("%s repositories:", position) @@ -237,7 +237,7 @@ function main() -- list all repositories elseif option.get("list") then - _list() + _list(option.get("global")) -- show repo directory else |
