diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2012-02-14 16:41:35 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2012-02-14 16:41:35 -0200 |
commit | 4ac89c833c98c3cd522ae00c7bc7bb2860b8056d (patch) | |
tree | 7e031833049fd9d43142c55a534775cdbd148126 | |
parent | 10375ec4bb162f2b992fbe477d609aa59096d7de (diff) | |
download | luarocks-4ac89c833c98c3cd522ae00c7bc7bb2860b8056d.tar.gz luarocks-4ac89c833c98c3cd522ae00c7bc7bb2860b8056d.tar.bz2 luarocks-4ac89c833c98c3cd522ae00c7bc7bb2860b8056d.zip |
Nicer looking help, inspired by man pages.
-rw-r--r-- | src/luarocks/download.lua | 5 | ||||
-rw-r--r-- | src/luarocks/help.lua | 74 |
2 files changed, 47 insertions, 32 deletions
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 6ae5f7af..268dc113 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
@@ -9,11 +9,12 @@ local fetch = require("luarocks.fetch") | |||
9 | local search = require("luarocks.search") | 9 | local search = require("luarocks.search") |
10 | 10 | ||
11 | help_summary = "Download a specific rock file from a rocks server." | 11 | help_summary = "Download a specific rock file from a rocks server." |
12 | help_arguments = "[--all] [--source] [--arch=<arch>] [<name> [<version>]]" | 12 | help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" |
13 | 13 | ||
14 | help = [[ | 14 | help = [[ |
15 | --all Download multiple rock files if there is more than one match. | 15 | --all Download all files if there are multiple matches. |
16 | --source Download .src.rock if available. | 16 | --source Download .src.rock if available. |
17 | --rockspec Download .rockspec if available. | ||
17 | --arch=<arch> Download rock for a specific architecture. | 18 | --arch=<arch> Download rock for a specific architecture. |
18 | ]] | 19 | ]] |
19 | 20 | ||
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 6272d213..3a366f44 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -9,13 +9,21 @@ module("luarocks.help", package.seeall) | |||
9 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
10 | local cfg = require("luarocks.cfg") | 10 | local cfg = require("luarocks.cfg") |
11 | 11 | ||
12 | help_summary = "Help on commands." | 12 | help_summary = "Help on commands. Type '"..program_name.." help <command>' for more." |
13 | 13 | ||
14 | help_arguments = "[<command>]" | 14 | help_arguments = "[<command>]" |
15 | help = [[ | 15 | help = [[ |
16 | <command> is the command to show help for. | 16 | <command> is the command to show help for. |
17 | ]] | 17 | ]] |
18 | 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 | |||
19 | --- Driver function for the "help" command. | 27 | --- Driver function for the "help" command. |
20 | -- @param command string or nil: command to show help for; if not | 28 | -- @param command string or nil: command to show help for; if not |
21 | -- given, help summaries for all commands are shown. | 29 | -- given, help summaries for all commands are shown. |
@@ -26,30 +34,28 @@ function run(...) | |||
26 | 34 | ||
27 | if not command then | 35 | if not command then |
28 | local sys_file, sys_ok, home_file, home_ok = cfg.which_config() | 36 | local sys_file, sys_ok, home_file, home_ok = cfg.which_config() |
37 | print_banner() | ||
38 | print_section("NAME") | ||
39 | util.printout("\t"..program_name..[[ - ]]..program_description) | ||
40 | print_section("SYNOPSIS") | ||
41 | util.printout("\t"..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]]) | ||
42 | print_section("GENERAL OPTIONS") | ||
29 | util.printout([[ | 43 | util.printout([[ |
30 | LuaRocks ]]..cfg.program_version..[[, a module deployment system for Lua | 44 | These apply to all commands, as appropriate: |
31 | |||
32 | Using system configuration file: ]]..sys_file .. " (" .. (sys_ok and "ok" or "failed") ..[[) | ||
33 | and user configuration file: ]]..home_file .. " (" .. (home_ok and "ok" or "failed") ..[[) | ||
34 | |||
35 | ]]..program_name..[[ - ]]..program_description..[[ | ||
36 | 45 | ||
37 | usage: ]]..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] | 46 | --server=<server> Fetch rocks/rockspecs from this server |
38 | 47 | (takes priority over config file) | |
39 | Variables from the "variables" table of the configuration file | 48 | --only-server=<server> Fetch rocks/rockspecs from this server only |
40 | can be overriden with VAR=VALUE assignments. | 49 | (overrides any entries in the config file) |
41 | 50 | --only-sources=<url> Restrict downloads to paths matching the | |
42 | --server=<server> Fetch rocks/rockspecs from this server | 51 | given URL. |
43 | (takes priority over config file) | 52 | --tree=<tree> Which tree to operate on. |
44 | --only-server=<server> Fetch rocks/rockspecs from this server only | 53 | --local Use the tree in the user's home directory.]]) |
45 | (overrides any entries in the config file) | 54 | print_section("VARIABLES") |
46 | --only-sources=<url> Restrict downloads to paths matching the | 55 | util.printout([[ |
47 | given URL. | 56 | Variables from the "variables" table of the configuration file |
48 | --tree=<tree> Which tree to operate on. | 57 | can be overriden with VAR=VALUE assignments.]]) |
49 | --local Use the tree in the user's home directory. | 58 | print_section("COMMANDS") |
50 | |||
51 | Supported commands: | ||
52 | ]]) | ||
53 | local names = {} | 59 | local names = {} |
54 | for name, command in pairs(commands) do | 60 | for name, command in pairs(commands) do |
55 | table.insert(names, name) | 61 | table.insert(names, name) |
@@ -57,18 +63,26 @@ Supported commands: | |||
57 | table.sort(names) | 63 | table.sort(names) |
58 | for _, name in ipairs(names) do | 64 | for _, name in ipairs(names) do |
59 | local command = commands[name] | 65 | local command = commands[name] |
60 | util.printout(name, command.help_summary) | 66 | util.printout("", name) |
67 | util.printout("\t", command.help_summary) | ||
61 | end | 68 | end |
69 | print_section("CONFIGURATION") | ||
70 | util.printout([[ | ||
71 | Using system configuration file: ]]..sys_file .. " (" .. (sys_ok and "ok" or "failed") ..[[) | ||
72 | and user configuration file: ]]..home_file .. " (" .. (home_ok and "ok" or "failed") ..")\n") | ||
62 | else | 73 | else |
63 | command = command:gsub("-", "_") | 74 | command = command:gsub("-", "_") |
64 | if commands[command] then | 75 | if commands[command] then |
65 | local arguments = commands[command].help_arguments or "<argument>" | 76 | local arguments = commands[command].help_arguments or "<argument>" |
66 | util.printout() | 77 | print_banner() |
67 | util.printout(program_name.." "..command.." "..arguments) | 78 | print_section("NAME") |
68 | util.printout() | 79 | util.printout("\t"..program_name.." "..command.." - "..commands[command].help_summary) |
69 | util.printout(command.." - "..commands[command].help_summary) | 80 | print_section("SYNOPSIS") |
70 | util.printout() | 81 | util.printout("\t"..program_name.." "..command.." "..arguments) |
71 | util.printout(commands[command].help) | 82 | print_section("DESCRIPTION") |
83 | util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$",""))) | ||
84 | print_section("SEE ALSO") | ||
85 | util.printout("","'luarocks help' for general options and configuration.\n") | ||
72 | else | 86 | else |
73 | return nil, "Unknown command '"..command.."'" | 87 | return nil, "Unknown command '"..command.."'" |
74 | end | 88 | end |