diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-05-27 15:19:42 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-05-27 15:19:42 +0100 |
commit | ac6a6b37ad417e24c137af32b06bfed1d6e2241d (patch) | |
tree | c701a6435c9eac13b4070ca2539153772fc00410 /lib/gitano/command.lua | |
parent | c3b78f172cf31ca7bebb3c72ccad1bbe7b56c240 (diff) | |
download | gitano-ac6a6b37ad417e24c137af32b06bfed1d6e2241d.tar.gz |
COMMANDS: Add destroy command
Diffstat (limited to 'lib/gitano/command.lua')
-rw-r--r-- | lib/gitano/command.lua | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index 7182e99..b327e73 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -404,6 +404,71 @@ assert(register_cmd("readme", builtin_readme_short, builtin_readme_prep, builtin_readme_run, true, false)) +local builtin_destroy_short = "Destroy (delete) a repository" +local builtin_destroy_helptext = [[ +usage: destroy <repo> [confirmtoken] + +This command destroys a repository. Run without a confirmation token +it will tell the caller what the confirmation token is for that repository. +The caller will then run the destroy command again with the confirmation +token if they really do wish to destroy the repository. +]] + +local function builtin_destroy_validate(config, repo, cmdline) + if #cmdline < 2 or #cmdline > 3 then + log.error("Destroy takes a repository and a (optional) confirmation token") + return false + end + if not repo or repo.is_nascent then + log.error("Cannot destroy a repository which does not exist") + return false + end + return true +end + +local function builtin_destroy_prep(config, repo, cmdline, context) + context.operation = "destroy" + return repo:run_lace(context) +end + +local function builtin_destroy_run(config, repo, cmdline, env) + if #cmdline == 2 then + -- Generate the confirmation token + local token = repo:generate_confirmation() + log.chat("") + log.chat("If you are *certain* you wish to destroy this repository") + log.chat("Then re-run your command with the following confirmation token:") + log.chat("") + log.chat(" ", token) + else + local token = repo:generate_confirmation() + if cmdline[3] ~= token then + log.error("Confirmation token does not match, refusing to destroy") + return "exit", 1 + end + -- Tokens match, ask the repo to destroy itself + local nowstamp = os.date("!%Y-%m-%d.%k:%M:%S.UTC") + local ok, msg = repo:destroy_self(nowstamp .. "." .. + (repo.name:gsub("[^A-Za-z0-9_%.%-]", + "_")) .. + "." .. token .. ".destroyed") + if not ok then + log.error(msg) + return "exit", 1 + end + log.chat("Successfully destroyed", repo.name) + log.chat("You will need to speak to an admin as soon as possible,") + log.chat("should you need to recover it. If you do, be sure to include a") + log.chat("note of the current time (" .. nowstamp .. ") when you do.") + end + return "exit", 0 +end + +assert(register_cmd("destroy", builtin_destroy_short, + builtin_destroy_helptext, builtin_destroy_validate, + builtin_destroy_prep, builtin_destroy_run, + true, false)) + return { register = register_cmd, get = get_cmd, |