Skip to content
Permalink
Browse files
Improve "see help" messages and always use the name by which the luar…
…ocks program was launched.
  • Loading branch information
hishamhm committed Apr 18, 2013
1 parent 6cc2c25 commit 99dcdc2
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 22 deletions.
@@ -2,7 +2,6 @@

local command_line = require("luarocks.command_line")

program_name = "luarocks"
program_description = "LuaRocks main command-line interface"

commands = {}
@@ -2,7 +2,6 @@

local command_line = require("luarocks.command_line")

program_name = "luarocks-admin"
program_description = "LuaRocks repository administration interface"

commands = {
@@ -99,7 +99,7 @@ function run(...)
local files = { util.parse_flags(...) }
local flags = table.remove(files, 1)
if #files < 1 then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("add", "luarocks-admin")
end
local server, server_table = cache.get_upload_server(flags["server"])
if not server then return nil, server_table end
@@ -78,7 +78,7 @@ function run(...)
local files = { util.parse_flags(...) }
local flags = table.remove(files, 1)
if #files < 1 then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin")
end
local server, server_table = cache.get_upload_server(flags["server"])
if not server then return nil, server_table end
@@ -321,7 +321,7 @@ end
function run(...)
local flags, name, version = util.parse_flags(...)
if type(name) ~= "string" then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("build")
end
assert(type(version) == "string" or not version)

@@ -8,6 +8,8 @@ local path = require("luarocks.path")
local dir = require("luarocks.dir")
local deps = require("luarocks.deps")

local program = util.this_program("luarocks")

--- Display an error message and exit.
-- @param message string: The error message.
local function die(message)
@@ -60,7 +62,7 @@ function run_command(...)
local command

if flags["version"] then
util.printout(program_name.." "..cfg.program_version)
util.printout(program.." "..cfg.program_version)
util.printout(program_description)
util.printout()
os.exit(0)
@@ -9,7 +9,9 @@ module("luarocks.help", package.seeall)
local util = require("luarocks.util")
local cfg = require("luarocks.cfg")

help_summary = "Help on commands. Type '"..program_name.." help <command>' for more."
local program = util.this_program("luarocks")

help_summary = "Help on commands. Type '"..program.." help <command>' for more."

help_arguments = "[<command>]"
help = [[
@@ -46,9 +48,9 @@ function run(...)
local sys_file, sys_ok, home_file, home_ok = cfg.which_config()
print_banner()
print_section("NAME")
util.printout("\t"..program_name..[[ - ]]..program_description)
util.printout("\t"..program..[[ - ]]..program_description)
print_section("SYNOPSIS")
util.printout("\t"..program_name..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]])
util.printout("\t"..program..[[ [--from=<server> | --only-from=<server>] [--to=<tree>] [VAR=VALUE]... <command> [<argument>] ]])
print_section("GENERAL OPTIONS")
util.printout([[
These apply to all commands, as appropriate:
@@ -60,7 +62,8 @@ function run(...)
--only-sources=<url> Restrict downloads to paths matching the
given URL.
--tree=<tree> Which tree to operate on.
--local Use the tree in the user's home directory.]])
--local Use the tree in the user's home directory.
To enable it, see ']]..program..[[ help path'.]])
print_section("VARIABLES")
util.printout([[
Variables from the "variables" table of the configuration file
@@ -86,13 +89,13 @@ function run(...)
local arguments = commands[command].help_arguments or "<argument>"
print_banner()
print_section("NAME")
util.printout("\t"..program_name.." "..command.." - "..commands[command].help_summary)
util.printout("\t"..program.." "..command.." - "..commands[command].help_summary)
print_section("SYNOPSIS")
util.printout("\t"..program_name.." "..command.." "..arguments)
util.printout("\t"..program.." "..command.." "..arguments)
print_section("DESCRIPTION")
util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$","")))
print_section("SEE ALSO")
util.printout("","'luarocks help' for general options and configuration.\n")
util.printout("","'"..program.." help' for general options and configuration.\n")
else
return nil, "Unknown command '"..command.."'"
end
@@ -118,7 +118,7 @@ end
function run(...)
local flags, name, version = util.parse_flags(...)
if type(name) ~= "string" then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("install")
end

local ok, err = fs.check_command_permissions(flags)
@@ -20,7 +20,7 @@ function run(...)
local flags, input = util.parse_flags(...)

if not input then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("lint")
end

local filename = input
@@ -55,7 +55,7 @@ function run(...)
end
end
if not rockspec:match("rockspec$") then
return nil, "Invalid argument: 'make' takes a rockspec as a parameter. See help."
return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make")
end

if flags["pack-binary-rock"] then
@@ -80,7 +80,7 @@ end
function run(...)
local flags, input, version, url = util.parse_flags(...)
if not input then
return nil, "Missing arguments: expected program or rockspec. See help."
return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version")
end
assert(type(input) == "string")

@@ -187,7 +187,7 @@ function run(...)
local flags, arg, version = util.parse_flags(...)
assert(type(version) == "string" or not version)
if type(arg) ~= "string" then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("pack")
end

local file, err
@@ -27,7 +27,7 @@ function run(...)
local tree = flags["tree"]

if type(tree) ~= "string" then
return nil, "The --tree argument is mandatory, see help."
return nil, "The --tree argument is mandatory. "..util.see_help("purge")
end

local results = {}
@@ -365,7 +365,7 @@ function run(...)
end

if type(name) ~= "string" and not flags["all"] then
return nil, "Enter name and version or use --all; see help."
return nil, "Enter name and version or use --all. "..util.see_help("search")
end

local query = make_query(name:lower(), version)
@@ -73,7 +73,7 @@ end
function run(...)
local flags, name, version = util.parse_flags(...)
if not name then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("show")
end
local results = {}
local query = search.make_query(name, version)
@@ -139,7 +139,7 @@ function run(...)

assert(type(version) == "string" or not version)
if type(name) ~= "string" then
return nil, "Argument missing, see help."
return nil, "Argument missing. "..util.see_help("unpack")
end

if name:match(".*%.rock") or name:match(".*%.rockspec") then
@@ -9,6 +9,7 @@ local global_env = _G
module("luarocks.util", package.seeall)

local scheduled_functions = {}
local debug = require("debug")

--- Schedule a function to be executed upon program termination.
-- This is useful for actions such as deleting temporary directories
@@ -316,6 +317,23 @@ function title(msg, porcelain, underline)
printout()
end

function this_program(default)
local i = 1
local last, cur = default, default
while i do
local dbg = debug.getinfo(i,"S")
if not dbg then break end
last = cur
cur = dbg.source
i=i+1
end
return last:sub(2)
end

function see_help(command, program)
return "See '"..this_program(program or "luarocks")..' help '..command.."'."
end

-- from http://lua-users.org/wiki/SplitJoin
-- by PhilippeLhoste
function split_string(str, delim, maxNb)

0 comments on commit 99dcdc2

Please sign in to comment.