summaryrefslogtreecommitdiff
path: root/lib/gitano/command.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitano/command.lua')
-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