prosodyctl: Improved the 'remove' command
authorJoão Duarte <jvsDuarte08@gmail.com>
Wed, 17 Jul 2019 09:03:15 -0700
changeset 10148 48a62e2e2a63
parent 10147 a099bff1842d
child 10149 0fcd251a27e5
prosodyctl: Improved the 'remove' command
prosodyctl
--- a/prosodyctl	Wed Jul 17 03:45:26 2019 -0700
+++ b/prosodyctl	Wed Jul 17 09:03:15 2019 -0700
@@ -147,10 +147,20 @@
     show_usage([[make]], [[Removes a module installed in the wroking directory's plugins folder]]);
     return 1
   end
-  print("Removing "..arg[1].." from ./plugins")
-  os.execute("luarocks --tree='./plugins' remove "..arg[1])
-  print("Done!")
-  return 0
+  local flag = "--tree="
+  -- I'm considering the flag is the first, but there can be many flags
+  if arg[1] and arg[1]:sub(1, #flag) == flag then
+    local dir = arg[1]:match("=(.+)$")
+    print("Removing module "..arg[2].." at "..dir..", from luarocks repo")
+    -- These extra double brackets allow us to correctly process names with spaces
+    os.execute("luarocks remove --tree='"..dir.."' "..arg[2])
+    return 0;
+  else
+    print("Removing "..arg[1].." from ./plugins")
+    os.execute("luarocks --tree='"..prosody.paths.plugins.."' remove "..arg[1])
+    print("Done!")
+    return 0
+  end
 end
 
 function commands.install(arg)