aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-04-18 00:19:21 -0300
committerHisham Muhammad <hisham@gobolinux.org>2013-04-18 00:19:21 -0300
commit99dcdc22319f38051087ab6929cfec170d784f0c (patch)
treeb467addd49a643550ddc540452df0ff29cfd3bea
parent6cc2c255777d77a73197ed6b960f898391dabfe6 (diff)
downloadluarocks-99dcdc22319f38051087ab6929cfec170d784f0c.tar.gz
luarocks-99dcdc22319f38051087ab6929cfec170d784f0c.tar.bz2
luarocks-99dcdc22319f38051087ab6929cfec170d784f0c.zip
Improve "see help" messages and always use the name by which the luarocks program was launched.
-rwxr-xr-xsrc/bin/luarocks1
-rwxr-xr-xsrc/bin/luarocks-admin1
-rw-r--r--src/luarocks/add.lua2
-rw-r--r--src/luarocks/admin_remove.lua2
-rw-r--r--src/luarocks/build.lua2
-rw-r--r--src/luarocks/command_line.lua4
-rw-r--r--src/luarocks/help.lua17
-rw-r--r--src/luarocks/install.lua2
-rw-r--r--src/luarocks/lint.lua2
-rw-r--r--src/luarocks/make.lua2
-rw-r--r--src/luarocks/new_version.lua2
-rw-r--r--src/luarocks/pack.lua2
-rw-r--r--src/luarocks/purge.lua2
-rw-r--r--src/luarocks/search.lua2
-rw-r--r--src/luarocks/show.lua2
-rw-r--r--src/luarocks/unpack.lua2
-rw-r--r--src/luarocks/util.lua18
17 files changed, 43 insertions, 22 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks
index aaafb905..b64051d4 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -2,7 +2,6 @@
2 2
3local command_line = require("luarocks.command_line") 3local command_line = require("luarocks.command_line")
4 4
5program_name = "luarocks"
6program_description = "LuaRocks main command-line interface" 5program_description = "LuaRocks main command-line interface"
7 6
8commands = {} 7commands = {}
diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin
index 69814459..4c5613ca 100755
--- a/src/bin/luarocks-admin
+++ b/src/bin/luarocks-admin
@@ -2,7 +2,6 @@
2 2
3local command_line = require("luarocks.command_line") 3local command_line = require("luarocks.command_line")
4 4
5program_name = "luarocks-admin"
6program_description = "LuaRocks repository administration interface" 5program_description = "LuaRocks repository administration interface"
7 6
8commands = { 7commands = {
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index 48b9964c..30db9a48 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -99,7 +99,7 @@ function run(...)
99 local files = { util.parse_flags(...) } 99 local files = { util.parse_flags(...) }
100 local flags = table.remove(files, 1) 100 local flags = table.remove(files, 1)
101 if #files < 1 then 101 if #files < 1 then
102 return nil, "Argument missing, see help." 102 return nil, "Argument missing. "..util.see_help("add", "luarocks-admin")
103 end 103 end
104 local server, server_table = cache.get_upload_server(flags["server"]) 104 local server, server_table = cache.get_upload_server(flags["server"])
105 if not server then return nil, server_table end 105 if not server then return nil, server_table end
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua
index dc36e16e..c235776f 100644
--- a/src/luarocks/admin_remove.lua
+++ b/src/luarocks/admin_remove.lua
@@ -78,7 +78,7 @@ function run(...)
78 local files = { util.parse_flags(...) } 78 local files = { util.parse_flags(...) }
79 local flags = table.remove(files, 1) 79 local flags = table.remove(files, 1)
80 if #files < 1 then 80 if #files < 1 then
81 return nil, "Argument missing, see help." 81 return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin")
82 end 82 end
83 local server, server_table = cache.get_upload_server(flags["server"]) 83 local server, server_table = cache.get_upload_server(flags["server"])
84 if not server then return nil, server_table end 84 if not server then return nil, server_table end
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index d61d6611..83abbf8d 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -321,7 +321,7 @@ end
321function run(...) 321function run(...)
322 local flags, name, version = util.parse_flags(...) 322 local flags, name, version = util.parse_flags(...)
323 if type(name) ~= "string" then 323 if type(name) ~= "string" then
324 return nil, "Argument missing, see help." 324 return nil, "Argument missing. "..util.see_help("build")
325 end 325 end
326 assert(type(version) == "string" or not version) 326 assert(type(version) == "string" or not version)
327 327
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index 9e499fc2..d16ef8e2 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -8,6 +8,8 @@ local path = require("luarocks.path")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local deps = require("luarocks.deps") 9local deps = require("luarocks.deps")
10 10
11local program = util.this_program("luarocks")
12
11--- Display an error message and exit. 13--- Display an error message and exit.
12-- @param message string: The error message. 14-- @param message string: The error message.
13local function die(message) 15local function die(message)
@@ -60,7 +62,7 @@ function run_command(...)
60 local command 62 local command
61 63
62 if flags["version"] then 64 if flags["version"] then
63 util.printout(program_name.." "..cfg.program_version) 65 util.printout(program.." "..cfg.program_version)
64 util.printout(program_description) 66 util.printout(program_description)
65 util.printout() 67 util.printout()
66 os.exit(0) 68 os.exit(0)
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua
index 19cd7914..45fc3bb4 100644
--- a/src/luarocks/help.lua
+++ b/src/luarocks/help.lua
@@ -9,7 +9,9 @@ module("luarocks.help", package.seeall)
9local util = require("luarocks.util") 9local util = require("luarocks.util")
10local cfg = require("luarocks.cfg") 10local cfg = require("luarocks.cfg")
11 11
12help_summary = "Help on commands. Type '"..program_name.." help <command>' for more." 12local program = util.this_program("luarocks")
13
14help_summary = "Help on commands. Type '"..program.." help <command>' for more."
13 15
14help_arguments = "[<command>]" 16help_arguments = "[<command>]"
15help = [[ 17help = [[
@@ -46,9 +48,9 @@ function run(...)
46 local sys_file, sys_ok, home_file, home_ok = cfg.which_config() 48 local sys_file, sys_ok, home_file, home_ok = cfg.which_config()
47 print_banner() 49 print_banner()
48 print_section("NAME") 50 print_section("NAME")
49 util.printout("\t"..program_name..[[ - ]]..program_description) 51 util.printout("\t"..program..[[ - ]]..program_description)
50 print_section("SYNOPSIS") 52 print_section("SYNOPSIS")
51 util.printout("\t"..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]]) 53 util.printout("\t"..program..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]])
52 print_section("GENERAL OPTIONS") 54 print_section("GENERAL OPTIONS")
53 util.printout([[ 55 util.printout([[
54 These apply to all commands, as appropriate: 56 These apply to all commands, as appropriate:
@@ -60,7 +62,8 @@ function run(...)
60 --only-sources=<url> Restrict downloads to paths matching the 62 --only-sources=<url> Restrict downloads to paths matching the
61 given URL. 63 given URL.
62 --tree=<tree> Which tree to operate on. 64 --tree=<tree> Which tree to operate on.
63 --local Use the tree in the user's home directory.]]) 65 --local Use the tree in the user's home directory.
66 To enable it, see ']]..program..[[ help path'.]])
64 print_section("VARIABLES") 67 print_section("VARIABLES")
65 util.printout([[ 68 util.printout([[
66 Variables from the "variables" table of the configuration file 69 Variables from the "variables" table of the configuration file
@@ -86,13 +89,13 @@ function run(...)
86 local arguments = commands[command].help_arguments or "<argument>" 89 local arguments = commands[command].help_arguments or "<argument>"
87 print_banner() 90 print_banner()
88 print_section("NAME") 91 print_section("NAME")
89 util.printout("\t"..program_name.." "..command.." - "..commands[command].help_summary) 92 util.printout("\t"..program.." "..command.." - "..commands[command].help_summary)
90 print_section("SYNOPSIS") 93 print_section("SYNOPSIS")
91 util.printout("\t"..program_name.." "..command.." "..arguments) 94 util.printout("\t"..program.." "..command.." "..arguments)
92 print_section("DESCRIPTION") 95 print_section("DESCRIPTION")
93 util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$",""))) 96 util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$","")))
94 print_section("SEE ALSO") 97 print_section("SEE ALSO")
95 util.printout("","'luarocks help' for general options and configuration.\n") 98 util.printout("","'"..program.." help' for general options and configuration.\n")
96 else 99 else
97 return nil, "Unknown command '"..command.."'" 100 return nil, "Unknown command '"..command.."'"
98 end 101 end
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index e633ea23..c2a54482 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -118,7 +118,7 @@ end
118function run(...) 118function run(...)
119 local flags, name, version = util.parse_flags(...) 119 local flags, name, version = util.parse_flags(...)
120 if type(name) ~= "string" then 120 if type(name) ~= "string" then
121 return nil, "Argument missing, see help." 121 return nil, "Argument missing. "..util.see_help("install")
122 end 122 end
123 123
124 local ok, err = fs.check_command_permissions(flags) 124 local ok, err = fs.check_command_permissions(flags)
diff --git a/src/luarocks/lint.lua b/src/luarocks/lint.lua
index 61388af6..62ced64d 100644
--- a/src/luarocks/lint.lua
+++ b/src/luarocks/lint.lua
@@ -20,7 +20,7 @@ function run(...)
20 local flags, input = util.parse_flags(...) 20 local flags, input = util.parse_flags(...)
21 21
22 if not input then 22 if not input then
23 return nil, "Argument missing, see help." 23 return nil, "Argument missing. "..util.see_help("lint")
24 end 24 end
25 25
26 local filename = input 26 local filename = input
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index 69c2162f..027b9fa6 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -55,7 +55,7 @@ function run(...)
55 end 55 end
56 end 56 end
57 if not rockspec:match("rockspec$") then 57 if not rockspec:match("rockspec$") then
58 return nil, "Invalid argument: 'make' takes a rockspec as a parameter. See help." 58 return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make")
59 end 59 end
60 60
61 if flags["pack-binary-rock"] then 61 if flags["pack-binary-rock"] then
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index 66802f0b..b91f8aed 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -80,7 +80,7 @@ end
80function run(...) 80function run(...)
81 local flags, input, version, url = util.parse_flags(...) 81 local flags, input, version, url = util.parse_flags(...)
82 if not input then 82 if not input then
83 return nil, "Missing arguments: expected program or rockspec. See help." 83 return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version")
84 end 84 end
85 assert(type(input) == "string") 85 assert(type(input) == "string")
86 86
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index d8f0b2ef..eaa0e165 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -187,7 +187,7 @@ function run(...)
187 local flags, arg, version = util.parse_flags(...) 187 local flags, arg, version = util.parse_flags(...)
188 assert(type(version) == "string" or not version) 188 assert(type(version) == "string" or not version)
189 if type(arg) ~= "string" then 189 if type(arg) ~= "string" then
190 return nil, "Argument missing, see help." 190 return nil, "Argument missing. "..util.see_help("pack")
191 end 191 end
192 192
193 local file, err 193 local file, err
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua
index ca682f7d..6b094061 100644
--- a/src/luarocks/purge.lua
+++ b/src/luarocks/purge.lua
@@ -27,7 +27,7 @@ function run(...)
27 local tree = flags["tree"] 27 local tree = flags["tree"]
28 28
29 if type(tree) ~= "string" then 29 if type(tree) ~= "string" then
30 return nil, "The --tree argument is mandatory, see help." 30 return nil, "The --tree argument is mandatory. "..util.see_help("purge")
31 end 31 end
32 32
33 local results = {} 33 local results = {}
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 7db88d74..1fc1f9a1 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -365,7 +365,7 @@ function run(...)
365 end 365 end
366 366
367 if type(name) ~= "string" and not flags["all"] then 367 if type(name) ~= "string" and not flags["all"] then
368 return nil, "Enter name and version or use --all; see help." 368 return nil, "Enter name and version or use --all. "..util.see_help("search")
369 end 369 end
370 370
371 local query = make_query(name:lower(), version) 371 local query = make_query(name:lower(), version)
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
index a6a53d9a..536085a7 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/show.lua
@@ -73,7 +73,7 @@ end
73function run(...) 73function run(...)
74 local flags, name, version = util.parse_flags(...) 74 local flags, name, version = util.parse_flags(...)
75 if not name then 75 if not name then
76 return nil, "Argument missing, see help." 76 return nil, "Argument missing. "..util.see_help("show")
77 end 77 end
78 local results = {} 78 local results = {}
79 local query = search.make_query(name, version) 79 local query = search.make_query(name, version)
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua
index 4920d381..1db66bbb 100644
--- a/src/luarocks/unpack.lua
+++ b/src/luarocks/unpack.lua
@@ -139,7 +139,7 @@ function run(...)
139 139
140 assert(type(version) == "string" or not version) 140 assert(type(version) == "string" or not version)
141 if type(name) ~= "string" then 141 if type(name) ~= "string" then
142 return nil, "Argument missing, see help." 142 return nil, "Argument missing. "..util.see_help("unpack")
143 end 143 end
144 144
145 if name:match(".*%.rock") or name:match(".*%.rockspec") then 145 if name:match(".*%.rock") or name:match(".*%.rockspec") then
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index c44dc73d..c5095675 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -9,6 +9,7 @@ local global_env = _G
9module("luarocks.util", package.seeall) 9module("luarocks.util", package.seeall)
10 10
11local scheduled_functions = {} 11local scheduled_functions = {}
12local debug = require("debug")
12 13
13--- Schedule a function to be executed upon program termination. 14--- Schedule a function to be executed upon program termination.
14-- This is useful for actions such as deleting temporary directories 15-- This is useful for actions such as deleting temporary directories
@@ -316,6 +317,23 @@ function title(msg, porcelain, underline)
316 printout() 317 printout()
317end 318end
318 319
320function this_program(default)
321 local i = 1
322 local last, cur = default, default
323 while i do
324 local dbg = debug.getinfo(i,"S")
325 if not dbg then break end
326 last = cur
327 cur = dbg.source
328 i=i+1
329 end
330 return last:sub(2)
331end
332
333function see_help(command, program)
334 return "See '"..this_program(program or "luarocks")..' help '..command.."'."
335end
336
319-- from http://lua-users.org/wiki/SplitJoin 337-- from http://lua-users.org/wiki/SplitJoin
320-- by PhilippeLhoste 338-- by PhilippeLhoste
321function split_string(str, delim, maxNb) 339function split_string(str, delim, maxNb)