summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2014-03-10 14:59:48 +0000
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2014-03-11 14:04:48 +0000
commitb4e1b4a3ef063e8447bb5299c7ea40ba9296b35d (patch)
tree18ba88fbc3d2e5ec77f0fc6046cfdbda6338b67b
parent9a6a262606096b0392feab573c9a94f2ce3ee8fb (diff)
downloadgitano-b4e1b4a3ef063e8447bb5299c7ea40ba9296b35d.tar.gz
Configurable repository detection for commands
Up until now, all commands have been restricted to expecting the repository as the second argument *ONLY*. In order to better support other styles of command, this routine combines the behaviour of all places which currently look for the repository into one place. In addition, this means we can simplify several call sites. Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r--lib/gitano/command.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua
index e55fe33..468b34b 100644
--- a/lib/gitano/command.lua
+++ b/lib/gitano/command.lua
@@ -13,9 +13,27 @@ local sio = require "luxio.simple"
local cmds = {}
+local function default_detect_repo(config, parsed_cmdline)
+ local repo, msg
+ if #parsed_cmdline > 1 then
+ -- Acquire the repository object for the target repo from arg 2
+ repo, msg = repository.find(config, parsed_cmdline[2])
+ if not repo then
+ log.critical("Unable to locate repository.")
+ log.critical(" * " .. (tostring(msg)))
+ return nil, nil
+ end
+
+ if repo.is_nascent then
+ log.info("Repository " .. repo.name .. " is nascent")
+ end
+ end
+ return repo, parsed_cmdline
+end
+
local function register_cmd(cmdname, short, helptext,
validate_fn, prep_fn, run_fn,
- takes_repo, hidden, is_admin)
+ takes_repo, hidden, is_admin, detect_repo)
--[[
log.ddebug("Register command", cmdname)
if takes_repo then
@@ -35,7 +53,8 @@ local function register_cmd(cmdname, short, helptext,
hidden = hidden,
admin = is_admin,
short = short,
- helptext = helptext
+ helptext = helptext,
+ detect_repo = detect_repo or default_detect_repo
}
cmds[#cmds+1] = cmdname
table.sort(cmds)
@@ -52,6 +71,7 @@ local function get_cmd(cmdname)
prep = cmd.prep,
run = cmd.run,
takes_repo = cmd.takes_repo,
+ detect_repo = cmd.detect_repo
}
end