summaryrefslogtreecommitdiff
path: root/lib/gitano
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-05-21 17:45:50 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-05-21 17:45:50 +0100
commitabcc97dd2475b101b6173bee4ccda7f418be6f37 (patch)
tree1bb024a67b5d2bfd2af4b77cbc711431e895e362 /lib/gitano
parenta511e0859b02efe46ee5863ca6af578ccde06d91 (diff)
downloadgitano-abcc97dd2475b101b6173bee4ccda7f418be6f37.tar.gz
Add a readme command
Diffstat (limited to 'lib/gitano')
-rw-r--r--lib/gitano/command.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua
index 22decf0..5b1ebcc 100644
--- a/lib/gitano/command.lua
+++ b/lib/gitano/command.lua
@@ -363,6 +363,52 @@ assert(register_cmd("whoami", builtin_whoami_short, builtin_whoami_helptext,
builtin_whoami_prep, builtin_whoami_run, false, false))
+local builtin_readme_short = "View readme for a repository (if present)"
+local builtin_readme_helptext = [[
+usage: readme <reponame>
+
+Shows you the readme for the given repository. You must have read
+access to the repository in order to see it.
+]]
+
+local function builtin_readme_validate(config, repo, cmdline)
+ if #cmdline ~= 2 then
+ log.error("Expected repository not provided")
+ return false
+ end
+ if not repo or repo.is_nascent then
+ log.error("Repository does not exist")
+ return false
+ end
+ return true
+end
+
+local function builtin_readme_prep(config, repo, cmdline)
+ return {
+ ["operation"] = "read",
+ }
+end
+
+local function builtin_readme_run(config, repo, cmdline, env)
+ local t = repo.readme_mdwn
+ if t then
+ if not t:match("\n$") then
+ t = t .. "\n"
+ end
+ for l in t:gmatch("([^\n]*)\n") do
+ log.chat(l)
+ end
+ else
+ log.chat("# No README.mdwn found")
+ end
+ return "exit", 0
+end
+
+assert(register_cmd("readme", builtin_readme_short,
+ builtin_readme_helptext, builtin_readme_validate,
+ builtin_readme_prep, builtin_readme_run,
+ true, false))
+
return {
register = register_cmd,
get = get_cmd,