summaryrefslogtreecommitdiff
path: root/lib/gitano/command.lua
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-06-29 23:04:44 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-06-29 23:04:44 +0100
commit3b13d8680a57b9761b4cf61903f067ce1b62753b (patch)
treef1d7d7ba0302647078270efe11b5cc7c15c42ef9 /lib/gitano/command.lua
parentf862a5ee162fa129dc7fd2595011d78a8b8ff109 (diff)
downloadgitano-3b13d8680a57b9761b4cf61903f067ce1b62753b.tar.gz
LIB: Create an admin command module and move 'as' into it. Also ensure help distinguishes the admin commands
Diffstat (limited to 'lib/gitano/command.lua')
-rw-r--r--lib/gitano/command.lua42
1 files changed, 34 insertions, 8 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua
index 27072bf..55f78bc 100644
--- a/lib/gitano/command.lua
+++ b/lib/gitano/command.lua
@@ -14,7 +14,7 @@ local cmds = {}
local function register_cmd(cmdname, short, helptext,
validate_fn, prep_fn, run_fn,
- takes_repo, hidden)
+ takes_repo, hidden, is_admin)
--[[
log.ddebug("Register command", cmdname)
if takes_repo then
@@ -32,6 +32,7 @@ local function register_cmd(cmdname, short, helptext,
run = run_fn,
takes_repo = takes_repo,
hidden = hidden,
+ admin = is_admin,
short = short,
helptext = helptext
}
@@ -55,18 +56,25 @@ end
local builtin_help_short = "Ask for help"
local builtin_help_helptext = [[
-usage: help [cmd]
+usage: help [admin|command]
Without the command argument, lists all visible commands. With the
command argument, provides detailed help about the given command.
+
+If the command argument is specifically 'admin' then list the
+admin commands instead of the normal commands. If it is 'all' then
+list all the commands, even the hidden commands.
]]
local function builtin_help_validate(config, repo, cmdline)
if #cmdline > 2 then
- log.error("usage: help [cmd]")
+ log.error("usage: help [admin|command]")
return false
end
if #cmdline == 2 then
+ if cmdline[2] == "all" or cmdline[2] == "admin" then
+ return true
+ end
if not cmds[cmdline[2]] then
log.error("Unknown command:", help)
return false
@@ -80,12 +88,27 @@ local function builtin_help_prep(config, repo, cmdline, context)
end
local function builtin_help_run(config, repo, cmdline, env)
- if #cmdline == 1 then
+ local function do_want(cmd)
+ if cmdline[2] == "all" then
+ return true
+ end
+ if cmdline[2] == "admin" then
+ return cmd.admin
+ end
+ return not (cmd.hidden or cmd.admin)
+ end
+ local function do_sep(cmd)
+ local first = cmd.hidden and "-H" or "--"
+ local second = cmd.admin and "A-" or "--"
+ return first .. second
+ end
+ if #cmdline == 1 or cmdline[2] == "admin" or cmdline[2] == "all" then
-- List all commands
local maxcmdn = 0
for i = 1, #cmds do
local cmd = cmds[cmds[i]]
- if not cmd.hidden then
+ local wanted = do_want(cmd)
+ if wanted then
if #cmd.name > maxcmdn then
maxcmdn = #cmd.name
end
@@ -93,13 +116,14 @@ local function builtin_help_run(config, repo, cmdline, env)
end
for i = 1, #cmds do
local cmd = cmds[cmds[i]]
- if not cmd.hidden then
+ local wanted = do_want(cmd)
+ if wanted then
local gap = (" "):rep(maxcmdn - #cmd.name)
local desc = (cmd.short or "No description")
if cmd.takes_repo then
desc = desc .. " (Takes a repo)"
end
- log.state(gap .. cmd.name, "--", desc)
+ log.state(gap .. cmd.name, do_sep(cmd), desc)
end
end
else
@@ -108,7 +132,7 @@ local function builtin_help_run(config, repo, cmdline, env)
if cmd.takes_repo then
desc = desc .. " (Takes a repo)"
end
- log.state(cmd.name, "--", desc)
+ log.state(cmd.name, do_sep(cmd), desc)
if cmd.helptext then
log.state("")
for line in (cmd.helptext):gmatch("([^\n]*)\n") do
@@ -671,6 +695,8 @@ assert(register_cmd("count-objects", builtin_count_objects_short,
local usercmds = require 'gitano.usercommand'
usercmds.register(register_cmd)
+local admincmds = require 'gitano.admincommand'
+admincmds.register(register_cmd)
return {
register = register_cmd,