diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2013-05-27 12:00:54 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2013-05-27 12:00:54 +0100 |
commit | 0cf169dc677f423fb0b21406f81eb4d0f3b86078 (patch) | |
tree | 876f49fb2b3d3691476f651f46ab33d9b756d37c /lib/gitano/command.lua | |
parent | 09fb03e476f6b6c111ed3b8bd7d6d0911ab94f4f (diff) | |
download | gitano-0cf169dc677f423fb0b21406f81eb4d0f3b86078.tar.gz |
COMMAND: Add readme set subcommand
Add to the readme command the ability to alter the README of a repository.
Diffstat (limited to 'lib/gitano/command.lua')
-rw-r--r-- | lib/gitano/command.lua | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index c3fd108..80fa554 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -9,6 +9,7 @@ local util = require 'gitano.util' local repository = require 'gitano.repository' local sp = require "luxio.subprocess" +local sio = require "luxio.simple" local cmds = {} @@ -600,16 +601,22 @@ assert(register_cmd("config", builtin_config_short, builtin_config_validate, builtin_config_prep, builtin_config_run, true, false)) -local builtin_readme_short = "View readme for a repository (if present)" +local builtin_readme_short = "Access readme for a repository" local builtin_readme_helptext = [[ -usage: readme <reponame> +usage: readme <reponame> [set|show] -Shows you the readme for the given repository. You must have read -access to the repository in order to see it. +If you do not provide a sub-command, the readme command defaults to +showing you the readme for the given repository. To view the +readme you must have read access to the repository. + +If you provide the subcommand 'set' then the readme command reads +from the input stream and updates the readme in the repository. +You must have the right to alter the project readme in order to do +this. ]] local function builtin_readme_validate(config, repo, cmdline) - if #cmdline ~= 2 then + if #cmdline < 2 then log.error("Expected repository not provided") return false end @@ -617,25 +624,45 @@ local function builtin_readme_validate(config, repo, cmdline) log.error("Repository does not exist") return false end + if #cmdline > 3 then + log.error("usage: readme <reponame> [set|show]") + return false + end + if #cmdline == 2 then + cmdline[3] = "show" + end + if cmdline[3] ~= "set" and cmdline[3] ~= "show" then + log.error("usage: readme <reponame> [set|show]") + return false + end return true end local function builtin_readme_prep(config, repo, cmdline, context) - context.operation = "read" + if cmdline[3] == "show" then + context.operation = "read" + else + context.operation = "setreadme" + end return repo:run_lace(context) 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.state(l) + if cmdline[3] == "show" then + 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.state(l) + end + else + log.state("# No README.mdwn found") end else - log.state("# No README.mdwn found") + local readme = sio.stdin:read("*a") + repo:set_readme(readme) end return "exit", 0 end |