diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-10-29 21:57:07 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-10-29 21:57:07 -0200 |
commit | 1ab2ca97e9900747c2f08810c4a6ea823435588c (patch) | |
tree | 4ef6a0cc2637ae4fa4c0ee15895d79ed07c8f3d2 | |
parent | 98ef4bf021e8a9f8062514394e7bb166e6a0a892 (diff) | |
download | luarocks-1ab2ca97e9900747c2f08810c4a6ea823435588c.tar.gz luarocks-1ab2ca97e9900747c2f08810c4a6ea823435588c.tar.bz2 luarocks-1ab2ca97e9900747c2f08810c4a6ea823435588c.zip |
Fix handling of arguments.
-rw-r--r-- | src/luarocks/write_rockspec.lua | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 5b981563..f8035b8d 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
@@ -10,10 +10,12 @@ local type_check = require("luarocks.type_check") | |||
10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
11 | 11 | ||
12 | help_summary = "Write a template for a rockspec file." | 12 | help_summary = "Write a template for a rockspec file." |
13 | help_arguments = "[--output=<file> ...] <name> [<version>] [<url>|<path>]" | 13 | help_arguments = "[--output=<file> ...] [<name>] [<version>] {<url>|<path>}" |
14 | help = [[ | 14 | help = [[ |
15 | This command writes an initial version of a rockspec file, | 15 | This command writes an initial version of a rockspec file, |
16 | based on an URL or a local path. | 16 | based on an URL or a local path. You may use a relative path such as '.'. |
17 | If a local path is given, name and version arguments are mandatory. | ||
18 | For URLs, LuaRocks will attempt to infer name and version if not given. | ||
17 | 19 | ||
18 | If a repository URL is given with no version, it creates an 'scm' rock. | 20 | If a repository URL is given with no version, it creates an 'scm' rock. |
19 | 21 | ||
@@ -36,7 +38,7 @@ rockspec, and is not guaranteed to be complete or correct. | |||
36 | 38 | ||
37 | local function get_url(rockspec) | 39 | local function get_url(rockspec) |
38 | local url = rockspec.source.url | 40 | local url = rockspec.source.url |
39 | local file, temp_dir, err_code, err_file, err_temp_dir = fetch.fetch_sources(rockspec, true) | 41 | local file, temp_dir, err_code, err_file, err_temp_dir = fetch.fetch_sources(rockspec, false) |
40 | if err_code == "source.dir" then | 42 | if err_code == "source.dir" then |
41 | file, temp_dir = err_file, err_temp_dir | 43 | file, temp_dir = err_file, err_temp_dir |
42 | elseif not file then | 44 | elseif not file then |
@@ -185,40 +187,38 @@ local function rockspec_cleanup(rockspec) | |||
185 | end | 187 | end |
186 | 188 | ||
187 | function run(...) | 189 | function run(...) |
188 | local flags, name, version, local_dir = util.parse_flags(...) | 190 | local flags, name, version, url_or_dir = util.parse_flags(...) |
189 | 191 | ||
190 | if not name then | 192 | if not name then |
191 | return nil, "Missing arguments. "..util.see_help("write_rockspec") | 193 | return nil, "Missing arguments. "..util.see_help("write_rockspec") |
192 | end | 194 | end |
193 | 195 | ||
194 | if name and not version then | 196 | if name and not version then |
195 | local protocol, path = dir.split_url(name) | 197 | url_or_dir = name |
196 | if not fetch.is_basic_protocol(protocol) then | 198 | name = nil |
197 | local_dir = name | 199 | elseif not url_or_dir then |
198 | version = "scm" | 200 | url_or_dir = version |
199 | name = dir.base_name(name):gsub("%.[^.]+$", "") | 201 | end |
200 | elseif protocol ~= "file" then | 202 | |
201 | local_dir = name | 203 | local protocol, pathname = dir.split_url(url_or_dir) |
202 | local filename = dir.base_name(name) | 204 | if not fetch.is_basic_protocol(protocol) then |
203 | name, version = filename:match("(.*)-([^-]+)") | 205 | version = "scm" |
204 | if version then | 206 | if not name then |
205 | version = version:gsub(".[a-z]+$", ""):gsub(".tar$", "") | 207 | name = dir.base_name(url_or_dir):gsub("%.[^.]+$", "") |
206 | else | 208 | end |
207 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 209 | elseif protocol ~= "file" then |
208 | end | 210 | local filename = dir.base_name(url_or_dir) |
211 | local newname, newversion = filename:match("(.*)-([^-]+)") | ||
212 | if not name then | ||
213 | name = newname | ||
214 | end | ||
215 | if newversion then | ||
216 | version = newversion:gsub(".[a-z]+$", ""):gsub(".tar$", "") | ||
209 | else | 217 | else |
210 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 218 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") |
211 | end | 219 | end |
212 | end | 220 | elseif not version then |
213 | 221 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | |
214 | if not local_dir then | ||
215 | local protocol, path = dir.split_url(version) | ||
216 | if not fetch.is_basic_protocol(protocol) then | ||
217 | local_dir = version | ||
218 | version = "scm" | ||
219 | elseif protocol ~= "file" then | ||
220 | return nil, "Missing version argument. "..util.see_help("write_rockspec") | ||
221 | end | ||
222 | end | 222 | end |
223 | 223 | ||
224 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") | 224 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") |
@@ -240,13 +240,15 @@ function run(...) | |||
240 | build = {}, | 240 | build = {}, |
241 | } | 241 | } |
242 | path.configure_paths(rockspec) | 242 | path.configure_paths(rockspec) |
243 | rockspec.source.protocol = dir.split_url(local_dir) | 243 | rockspec.source.protocol = protocol |
244 | 244 | ||
245 | configure_lua_version(rockspec, flags["lua-version"]) | 245 | configure_lua_version(rockspec, flags["lua-version"]) |
246 | |||
247 | local local_dir = url_or_dir | ||
246 | 248 | ||
247 | if local_dir:match("://") then | 249 | if url_or_dir:match("://") then |
248 | rockspec.source.url = local_dir | 250 | rockspec.source.url = url_or_dir |
249 | rockspec.source.file = dir.base_name(local_dir) | 251 | rockspec.source.file = dir.base_name(url_or_dir) |
250 | rockspec.source.dir = "dummy" | 252 | rockspec.source.dir = "dummy" |
251 | if not fetch.is_basic_protocol(rockspec.source.protocol) then | 253 | if not fetch.is_basic_protocol(rockspec.source.protocol) then |
252 | if version ~= "scm" then | 254 | if version ~= "scm" then |
@@ -256,7 +258,7 @@ function run(...) | |||
256 | rockspec.source.dir = nil | 258 | rockspec.source.dir = nil |
257 | local ok, base_dir, temp_dir = get_url(rockspec) | 259 | local ok, base_dir, temp_dir = get_url(rockspec) |
258 | if ok then | 260 | if ok then |
259 | if base_dir ~= dir.base_name(local_dir) then | 261 | if base_dir ~= dir.base_name(url_or_dir) then |
260 | rockspec.source.dir = base_dir | 262 | rockspec.source.dir = base_dir |
261 | end | 263 | end |
262 | end | 264 | end |