comparison share/lua/5.2/luarocks/help.lua @ 1132:d137f631bad5

<GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
author HackBot
date Fri, 14 Dec 2012 22:24:27 +0000
parents
children
comparison
equal deleted inserted replaced
1131:ff65dfb63263 1132:d137f631bad5
1
2 --- Module implementing the LuaRocks "help" command.
3 -- This is a generic help display module, which
4 -- uses a global table called "commands" to find commands
5 -- to show help for; each command should be represented by a
6 -- table containing "help" and "help_summary" fields.
7 module("luarocks.help", package.seeall)
8
9 local util = require("luarocks.util")
10 local cfg = require("luarocks.cfg")
11
12 help_summary = "Help on commands. Type '"..program_name.." help <command>' for more."
13
14 help_arguments = "[<command>]"
15 help = [[
16 <command> is the command to show help for.
17 ]]
18
19 local function print_banner()
20 util.printout("\nLuaRocks "..cfg.program_version..", a module deployment system for Lua")
21 end
22
23 local function print_section(section)
24 util.printout("\n"..section)
25 end
26
27 local function get_status(status)
28 if status then
29 return "ok"
30 elseif status == false then
31 return "not found"
32 else
33 return "failed"
34 end
35 end
36
37 --- Driver function for the "help" command.
38 -- @param command string or nil: command to show help for; if not
39 -- given, help summaries for all commands are shown.
40 -- @return boolean or (nil, string): true if there were no errors
41 -- or nil and an error message if an invalid command was requested.
42 function run(...)
43 local flags, command = util.parse_flags(...)
44
45 if not command then
46 local sys_file, sys_ok, home_file, home_ok = cfg.which_config()
47 print_banner()
48 print_section("NAME")
49 util.printout("\t"..program_name..[[ - ]]..program_description)
50 print_section("SYNOPSIS")
51 util.printout("\t"..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]])
52 print_section("GENERAL OPTIONS")
53 util.printout([[
54 These apply to all commands, as appropriate:
55
56 --server=<server> Fetch rocks/rockspecs from this server
57 (takes priority over config file)
58 --only-server=<server> Fetch rocks/rockspecs from this server only
59 (overrides any entries in the config file)
60 --only-sources=<url> Restrict downloads to paths matching the
61 given URL.
62 --tree=<tree> Which tree to operate on.
63 --local Use the tree in the user's home directory.]])
64 print_section("VARIABLES")
65 util.printout([[
66 Variables from the "variables" table of the configuration file
67 can be overriden with VAR=VALUE assignments.]])
68 print_section("COMMANDS")
69 local names = {}
70 for name, command in pairs(commands) do
71 table.insert(names, name)
72 end
73 table.sort(names)
74 for _, name in ipairs(names) do
75 local command = commands[name]
76 util.printout("", name)
77 util.printout("\t", command.help_summary)
78 end
79 print_section("CONFIGURATION")
80 util.printout([[
81 System configuration file: ]]..sys_file .. " (" .. get_status(sys_ok) ..[[)
82 User configuration file: ]]..home_file .. " (" .. get_status(home_ok) ..")\n")
83 else
84 command = command:gsub("-", "_")
85 if commands[command] then
86 local arguments = commands[command].help_arguments or "<argument>"
87 print_banner()
88 print_section("NAME")
89 util.printout("\t"..program_name.." "..command.." - "..commands[command].help_summary)
90 print_section("SYNOPSIS")
91 util.printout("\t"..program_name.." "..command.." "..arguments)
92 print_section("DESCRIPTION")
93 util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$","")))
94 print_section("SEE ALSO")
95 util.printout("","'luarocks help' for general options and configuration.\n")
96 else
97 return nil, "Unknown command '"..command.."'"
98 end
99 end
100 return true
101 end