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