diff options
| -rw-r--r-- | src/luarocks/write_rockspec.lua | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 26a65808..abfca322 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
| @@ -12,14 +12,16 @@ local type_check = require("luarocks.type_check") | |||
| 12 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
| 13 | 13 | ||
| 14 | write_rockspec.help_summary = "Write a template for a rockspec file." | 14 | write_rockspec.help_summary = "Write a template for a rockspec file." |
| 15 | write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] {<url>|<path>}" | 15 | write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]" |
| 16 | write_rockspec.help = [[ | 16 | write_rockspec.help = [[ |
| 17 | This command writes an initial version of a rockspec file, | 17 | This command writes an initial version of a rockspec file, |
| 18 | based on an URL or a local path. You may use a relative path such as '.'. | 18 | based on a name, a version, and a location (an URL or a local path). |
| 19 | If a local path is given, name and version arguments are mandatory. | 19 | If only two arguments are given, the first one is considered the name and the |
| 20 | For URLs, LuaRocks will attempt to infer name and version if not given. | 20 | second one is the location. |
| 21 | 21 | If only one argument is given, it must be the location. | |
| 22 | If a repository URL is given with no version, it creates an 'scm' rock. | 22 | If no arguments are given, current directory is used as location. |
| 23 | LuaRocks will attempt to infer name and version if not given, | ||
| 24 | using 'scm' as default version. | ||
| 23 | 25 | ||
| 24 | Note that the generated file is a _starting point_ for writing a | 26 | Note that the generated file is a _starting point_ for writing a |
| 25 | rockspec, and is not guaranteed to be complete or correct. | 27 | rockspec, and is not guaranteed to be complete or correct. |
| @@ -198,19 +200,17 @@ end | |||
| 198 | 200 | ||
| 199 | function write_rockspec.run(...) | 201 | function write_rockspec.run(...) |
| 200 | local flags, name, version, url_or_dir = util.parse_flags(...) | 202 | local flags, name, version, url_or_dir = util.parse_flags(...) |
| 201 | |||
| 202 | if not name then | ||
| 203 | return nil, "Missing arguments. "..util.see_help("write_rockspec") | ||
| 204 | end | ||
| 205 | 203 | ||
| 206 | if name and not version then | 204 | if not name then |
| 205 | url_or_dir = "." | ||
| 206 | elseif not version then | ||
| 207 | url_or_dir = name | 207 | url_or_dir = name |
| 208 | name = nil | 208 | name = nil |
| 209 | elseif not url_or_dir then | 209 | elseif not url_or_dir then |
| 210 | url_or_dir = version | 210 | url_or_dir = version |
| 211 | version = nil | 211 | version = nil |
| 212 | end | 212 | end |
| 213 | 213 | ||
| 214 | if flags["tag"] then | 214 | if flags["tag"] then |
| 215 | if not version then | 215 | if not version then |
| 216 | version = flags["tag"]:gsub("^v", "") | 216 | version = flags["tag"]:gsub("^v", "") |
| @@ -218,28 +218,25 @@ function write_rockspec.run(...) | |||
| 218 | end | 218 | end |
| 219 | 219 | ||
| 220 | local protocol, pathname = dir.split_url(url_or_dir) | 220 | local protocol, pathname = dir.split_url(url_or_dir) |
| 221 | if not fetch.is_basic_protocol(protocol) then | 221 | if protocol == "file" then |
| 222 | if not name then | 222 | if pathname == "." then |
| 223 | name = dir.base_name(url_or_dir):gsub("%.[^.]+$", "") | 223 | name = name or dir.base_name(fs.current_dir()) |
| 224 | end | 224 | end |
| 225 | if not version then | 225 | elseif fetch.is_basic_protocol(protocol) then |
| 226 | version = "scm" | ||
| 227 | end | ||
| 228 | elseif protocol ~= "file" then | ||
| 229 | local filename = dir.base_name(url_or_dir) | 226 | local filename = dir.base_name(url_or_dir) |
| 230 | local newname, newversion = filename:match("(.*)-([^-]+)") | 227 | local newname, newversion = filename:match("(.*)-([^-]+)") |
| 231 | if (not name) and newname then | 228 | if newname then |
| 232 | name = newname | 229 | name = name or newname |
| 233 | end | 230 | version = version or newversion:gsub("%.[a-z]+$", ""):gsub("%.tar$", "") |
| 234 | if (not version) and newversion then | ||
| 235 | version = newversion:gsub(".[a-z]+$", ""):gsub(".tar$", "") | ||
| 236 | end | 231 | end |
| 237 | if not (name and version) then | 232 | else |
| 238 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 233 | name = name or dir.base_name(url_or_dir):gsub("%.[^.]+$", "") |
| 239 | end | 234 | end |
| 240 | elseif not version then | 235 | |
| 241 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 236 | if not name then |
| 237 | return nil, "Could not infer rock name. "..util.see_help("write_rockspec") | ||
| 242 | end | 238 | end |
| 239 | version = version or "scm" | ||
| 243 | 240 | ||
| 244 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") | 241 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") |
| 245 | 242 | ||
