Mercurial > prosody-hg
comparison util/prosodyctl.lua @ 11132:287d0d80aa57
util.prosodyctl: Construct luarocks command line with templates
More flexible and safer wrt escaping
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 05 Oct 2020 21:13:23 +0200 |
| parents | e5dee71d0ebb |
| children | 624eafed3343 |
comparison
equal
deleted
inserted
replaced
| 11131:40abef01f4b9 | 11132:287d0d80aa57 |
|---|---|
| 10 local config = require "core.configmanager"; | 10 local config = require "core.configmanager"; |
| 11 local encodings = require "util.encodings"; | 11 local encodings = require "util.encodings"; |
| 12 local stringprep = encodings.stringprep; | 12 local stringprep = encodings.stringprep; |
| 13 local storagemanager = require "core.storagemanager"; | 13 local storagemanager = require "core.storagemanager"; |
| 14 local usermanager = require "core.usermanager"; | 14 local usermanager = require "core.usermanager"; |
| 15 local interpolation = require "util.interpolation"; | |
| 15 local signal = require "util.signal"; | 16 local signal = require "util.signal"; |
| 16 local set = require "util.set"; | 17 local set = require "util.set"; |
| 17 local lfs = require "lfs"; | 18 local lfs = require "lfs"; |
| 18 local type = type; | 19 local type = type; |
| 19 | 20 |
| 222 for path in plugin_paths:gmatch("[^;]+") do | 223 for path in plugin_paths:gmatch("[^;]+") do |
| 223 return path; | 224 return path; |
| 224 end | 225 end |
| 225 end | 226 end |
| 226 | 227 |
| 228 local render_cli = interpolation.new("%b{}", function (s) return "'"..s:gsub("'","'\\''").."'" end) | |
| 229 | |
| 227 local function call_luarocks(mod, operation) | 230 local function call_luarocks(mod, operation) |
| 228 local dir = get_path_custom_plugins(prosody.paths.plugins); | 231 local dir = get_path_custom_plugins(prosody.paths.plugins); |
| 229 if operation == "install" then | 232 if operation == "install" then |
| 230 show_message("Installing %s at %s", mod, dir); | 233 show_message("Installing %s at %s", mod, dir); |
| 231 elseif operation == "remove" then | 234 elseif operation == "remove" then |
| 232 show_message("Removing %s from %s", mod, dir); | 235 show_message("Removing %s from %s", mod, dir); |
| 233 end | 236 end |
| 234 if operation == "list" then | 237 if operation == "list" then |
| 235 os.execute("luarocks list --tree='"..dir.."'") | 238 os.execute(render_cli("luarocks list --tree={dir}", {dir = dir})); |
| 236 else | 239 else |
| 237 os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); | 240 os.execute(render_cli("luarocks {op} --tree={dir} {server&--server={server}} {mod}", { |
| 241 dir = dir; op = operation; mod = mod; server = "http://localhost/"; | |
| 242 })); | |
| 238 end | 243 end |
| 239 if operation == "install" then | 244 if operation == "install" then |
| 240 show_module_configuration_help(mod); | 245 show_module_configuration_help(mod); |
| 241 end | 246 end |
| 242 end | 247 end |
