aboutsummaryrefslogtreecommitdiff
path: root/src/luarocks/command_line.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/luarocks/command_line.lua')
-rw-r--r--src/luarocks/command_line.lua37
1 files changed, 6 insertions, 31 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index b3284534..1a8c0fe7 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -27,20 +27,9 @@ local function die(message, exitcode)
27 os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) 27 os.exit(exitcode or cfg.errorcodes.UNSPECIFIED)
28end 28end
29 29
30local function replace_tree(flags, args, tree) 30local function replace_tree(flags, tree)
31 tree = dir.normalize(tree) 31 tree = dir.normalize(tree)
32 flags["tree"] = tree 32 flags["tree"] = tree
33 local added = false
34 for i = 1, #args do
35 if args[i]:match("%-%-tree=") then
36 args[i] = "--tree="..tree
37 added = true
38 break
39 end
40 end
41 if not added then
42 args[#args + 1] = "--tree="..tree
43 end
44 path.use_tree(tree) 33 path.use_tree(tree)
45end 34end
46 35
@@ -78,7 +67,6 @@ function command_line.run_command(...)
78 if flags["to"] then flags["tree"] = flags["to"] end 67 if flags["to"] then flags["tree"] = flags["to"] end
79 if flags["nodeps"] then 68 if flags["nodeps"] then
80 flags["deps-mode"] = "none" 69 flags["deps-mode"] = "none"
81 table.insert(args, "--deps-mode=none")
82 end 70 end
83 71
84 cfg.flags = flags 72 cfg.flags = flags
@@ -106,15 +94,8 @@ function command_line.run_command(...)
106 os.exit(cfg.errorcodes.OK) 94 os.exit(cfg.errorcodes.OK)
107 elseif flags["help"] or #nonflags == 0 then 95 elseif flags["help"] or #nonflags == 0 then
108 command = "help" 96 command = "help"
109 args = nonflags
110 else 97 else
111 command = nonflags[1] 98 command = table.remove(nonflags, 1)
112 for i, arg in ipairs(args) do
113 if arg == command then
114 table.remove(args, i)
115 break
116 end
117 end
118 end 99 end
119 command = command:gsub("-", "_") 100 command = command:gsub("-", "_")
120 101
@@ -137,14 +118,14 @@ function command_line.run_command(...)
137 if not tree.root then 118 if not tree.root then
138 die("Configuration error: tree '"..tree.name.."' has no 'root' field.") 119 die("Configuration error: tree '"..tree.name.."' has no 'root' field.")
139 end 120 end
140 replace_tree(flags, args, tree.root) 121 replace_tree(flags, tree.root)
141 named = true 122 named = true
142 break 123 break
143 end 124 end
144 end 125 end
145 if not named then 126 if not named then
146 local root_dir = fs.absolute_name(flags["tree"]) 127 local root_dir = fs.absolute_name(flags["tree"])
147 replace_tree(flags, args, root_dir) 128 replace_tree(flags, root_dir)
148 end 129 end
149 elseif flags["local"] then 130 elseif flags["local"] then
150 if not cfg.home_tree then 131 if not cfg.home_tree then
@@ -152,7 +133,7 @@ function command_line.run_command(...)
152 "You are running as a superuser, which is intended for system-wide operation.\n".. 133 "You are running as a superuser, which is intended for system-wide operation.\n"..
153 "To force using the superuser's home, use --tree explicitly.") 134 "To force using the superuser's home, use --tree explicitly.")
154 end 135 end
155 replace_tree(flags, args, cfg.home_tree) 136 replace_tree(flags, cfg.home_tree)
156 else 137 else
157 local trees = cfg.rocks_trees 138 local trees = cfg.rocks_trees
158 path.use_tree(trees[#trees]) 139 path.use_tree(trees[#trees])
@@ -195,14 +176,8 @@ function command_line.run_command(...)
195 end 176 end
196 177
197 if commands[command] then 178 if commands[command] then
198 -- TODO the interface of run should be modified, to receive the
199 -- flags table and the (possibly unpacked) nonflags arguments.
200 -- This would remove redundant parsing of arguments.
201 -- I'm not changing this now to avoid messing with the run()
202 -- interface, which I know some people use (even though
203 -- I never published it as a public API...)
204 local cmd = require(commands[command]) 179 local cmd = require(commands[command])
205 local xp, ok, err, exitcode = xpcall(function() return cmd.run(unpack(args)) end, function(err) 180 local xp, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, function(err)
206 die(debug.traceback("LuaRocks "..cfg.program_version 181 die(debug.traceback("LuaRocks "..cfg.program_version
207 .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n" 182 .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n"
208 ..err, 2), cfg.errorcodes.CRASH) 183 ..err, 2), cfg.errorcodes.CRASH)