diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-12-19 18:05:46 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-01-10 16:41:38 -0200 |
| commit | bac6b52d0498ec1c8ae5f81847c0332324566c03 (patch) | |
| tree | 06fd802bb292f304b0d3531be33d089d395cfd27 /src | |
| parent | 5592cbcadfb44c914427a0d538c30f56da1997e1 (diff) | |
| download | luarocks-bac6b52d0498ec1c8ae5f81847c0332324566c03.tar.gz luarocks-bac6b52d0498ec1c8ae5f81847c0332324566c03.tar.bz2 luarocks-bac6b52d0498ec1c8ae5f81847c0332324566c03.zip | |
Enhancements for `luarocks doc` UI
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/doc.lua | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index e6d9c58a..c2989f98 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua | |||
| @@ -19,6 +19,7 @@ using a series of heuristics. | |||
| 19 | With these flags, return only the desired information: | 19 | With these flags, return only the desired information: |
| 20 | 20 | ||
| 21 | --home Open the home page of project. | 21 | --home Open the home page of project. |
| 22 | --list List documentation files only. | ||
| 22 | 23 | ||
| 23 | For more information about a rock, see the 'show' command. | 24 | For more information about a rock, see the 'show' command. |
| 24 | ]] | 25 | ]] |
| @@ -63,6 +64,7 @@ function run(...) | |||
| 63 | break | 64 | break |
| 64 | end | 65 | end |
| 65 | end | 66 | end |
| 67 | docdir = dir.normalize(docdir):gsub("/+", "/") | ||
| 66 | if not docdir then | 68 | if not docdir then |
| 67 | if descript.homepage then | 69 | if descript.homepage then |
| 68 | util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") | 70 | util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") |
| @@ -73,9 +75,29 @@ function run(...) | |||
| 73 | end | 75 | end |
| 74 | 76 | ||
| 75 | local files = fs.find(docdir) | 77 | local files = fs.find(docdir) |
| 76 | local extensions = { "%.htm", "%.md", "%.txt", "%.textile", "" } | 78 | local htmlpatt = "%.html?$" |
| 79 | local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } | ||
| 77 | local basenames = { "index", "readme", "manual" } | 80 | local basenames = { "index", "readme", "manual" } |
| 78 | 81 | ||
| 82 | local porcelain = flags["porcelain"] | ||
| 83 | if #files > 0 then | ||
| 84 | util.title("Documentation files for "..name.." "..version, porcelain) | ||
| 85 | if porcelain then | ||
| 86 | for _, file in ipairs(files) do | ||
| 87 | util.printout(docdir.."/"..file) | ||
| 88 | end | ||
| 89 | else | ||
| 90 | util.printout(docdir.."/") | ||
| 91 | for _, file in ipairs(files) do | ||
| 92 | util.printout("\t"..file) | ||
| 93 | end | ||
| 94 | end | ||
| 95 | end | ||
| 96 | |||
| 97 | if flags["list"] then | ||
| 98 | return true | ||
| 99 | end | ||
| 100 | |||
| 79 | for _, extension in ipairs(extensions) do | 101 | for _, extension in ipairs(extensions) do |
| 80 | for _, basename in ipairs(basenames) do | 102 | for _, basename in ipairs(basenames) do |
| 81 | local filename = basename..extension | 103 | local filename = basename..extension |
| @@ -87,8 +109,11 @@ function run(...) | |||
| 87 | end | 109 | end |
| 88 | if found then | 110 | if found then |
| 89 | local pathname = dir.path(docdir, found) | 111 | local pathname = dir.path(docdir, found) |
| 112 | util.printout() | ||
| 90 | util.printout("Opening "..pathname.." ...") | 113 | util.printout("Opening "..pathname.." ...") |
| 91 | if not fs.browser(pathname) then | 114 | util.printout() |
| 115 | local ok = fs.browser(pathname) | ||
| 116 | if not ok and not pathname:match(htmlpatt) then | ||
| 92 | local fd = io.open(pathname, "r") | 117 | local fd = io.open(pathname, "r") |
| 93 | util.printout(fd:read("*a")) | 118 | util.printout(fd:read("*a")) |
| 94 | fd:close() | 119 | fd:close() |
