aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-02-03 09:59:03 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-02-03 09:59:03 -0200
commita3b0f72ddedf1c7d6586632e8af416ea20854cf8 (patch)
tree1bc93e67f189f50a664ad77c36fa0d8ddd2bf914
parent735f794629ca8da96ba09a2d7ed789169bec9cf3 (diff)
downloadluarocks-a3b0f72ddedf1c7d6586632e8af416ea20854cf8.tar.gz
luarocks-a3b0f72ddedf1c7d6586632e8af416ea20854cf8.tar.bz2
luarocks-a3b0f72ddedf1c7d6586632e8af416ea20854cf8.zip
Make `luarocks doc` return something meaningful even for rocks that are not installed.
-rw-r--r--src/luarocks/doc.lua44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua
index 1a843f37..324bf028 100644
--- a/src/luarocks/doc.lua
+++ b/src/luarocks/doc.lua
@@ -9,6 +9,7 @@ local path = require("luarocks.path")
9local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
10local fetch = require("luarocks.fetch") 10local fetch = require("luarocks.fetch")
11local fs = require("luarocks.fs") 11local fs = require("luarocks.fs")
12local download = require("luarocks.download")
12 13
13help_summary = "Shows documentation for an installed rock." 14help_summary = "Shows documentation for an installed rock."
14 15
@@ -24,6 +25,33 @@ With these flags, return only the desired information:
24For more information about a rock, see the 'show' command. 25For more information about a rock, see the 'show' command.
25]] 26]]
26 27
28local function show_homepage(homepage, name, version)
29 if not homepage then
30 return nil, "No 'homepage' field in rockspec for "..name.." "..version
31 end
32 util.printout("Opening "..homepage.." ...")
33 fs.browser(homepage)
34 return true
35end
36
37local function try_to_open_homepage(name, version)
38 local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or ""))
39 if not temp_dir then
40 return nil, "Failed creating temporary directory: "..err
41 end
42 util.schedule_function(fs.delete, temp_dir)
43 local ok, err = fs.change_dir(temp_dir)
44 if not ok then return nil, err end
45 local filename, err = download.download("rockspec", name, version)
46 if not filename then return nil, err end
47 local rockspec, err = fetch.load_local_rockspec(filename)
48 if not rockspec then return nil, err end
49 fs.pop_dir()
50 local descript = rockspec.description or {}
51 if not descript.homepage then return nil, "No homepage defined for "..name end
52 return show_homepage(descript.homepage, name, version)
53end
54
27--- Driver function for "doc" command. 55--- Driver function for "doc" command.
28-- @param name or nil: an existing package name. 56-- @param name or nil: an existing package name.
29-- @param version string or nil: a version may also be passed. 57-- @param version string or nil: a version may also be passed.
@@ -34,23 +62,19 @@ function run(...)
34 return nil, "Argument missing. "..util.see_help("doc") 62 return nil, "Argument missing. "..util.see_help("doc")
35 end 63 end
36 64
37 local repo 65 local iname, iversion, repo = show.pick_installed_rock(name, version, flags["tree"])
38 name, version, repo = show.pick_installed_rock(name, version, flags["tree"]) 66 if not iname then
39 if not name then 67 util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...")
40 return nil, version 68 return try_to_open_homepage(name, version)
41 end 69 end
70 name, version = iname, iversion
42 71
43 local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo)) 72 local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo))
44 if not rockspec then return nil,err end 73 if not rockspec then return nil,err end
45 local descript = rockspec.description or {} 74 local descript = rockspec.description or {}
46 75
47 if flags["homepage"] then 76 if flags["homepage"] then
48 if not descript.homepage then 77 return show_homepage(descript.homepage, name, version)
49 return nil, "No 'homepage' field in rockspec for "..name.." "..version
50 end
51 util.printout("Opening "..descript.homepage.." ...")
52 fs.browser(descript.homepage)
53 return true
54 end 78 end
55 79
56 local directory = path.install_dir(name,version,repo) 80 local directory = path.install_dir(name,version,repo)