require 'clamp' require 'tempfile' require 'shellwords' require 'rugged' module Gisha class ReceiveCommand < Clamp::Command parameter 'KEY_ID', 'id to identify the key' def execute Commands::Receive.new(key_id).exec end end class AddKeyCommand < Clamp::Command parameter 'ID', 'id to identify the key' parameter 'KEY', 'public key that was provided to the server' parameter 'AUTH_FILE', 'file containing public keys for public key authentication;' def execute Commands::Key.new(auth_file, id, key).add end end class DeleleteKeyCommand < Clamp::Command parameter 'ID', 'id to identify the key' parameter 'AUTH_FILE', 'file containing public keys for public key authentication;' def execute Commands::Key.new(auth_file, id).del end end class CreateRepositoryCommand < Clamp::Command parameter 'PATH', 'path to create repository' def execute Rugged::Repository.init_at(path, :bare) FileUtils.cp("#{root_path}/hooks/update", "#{path}/hooks") end def root_path @root_path ||= File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) end end class DeleteRepositoryCommand < Clamp::Command parameter 'PATH', 'path to delete repository' def execute FileUtils.rm_rf(path) end end class DeployCommand < Clamp::Command parameter 'URL', 'url to deploy' parameter 'KEY_ID', 'id to identify the key' parameter 'PATH', 'repository path' parameter 'REVISION', 'repository path' def execute Commands::Deploy.new(url, key_id, path, revision).exec end end class CLI < Clamp::Command subcommand 'keys:add', 'add new key', AddKeyCommand subcommand 'keys:del', 'delete key', DeleleteKeyCommand subcommand 'repositories:create', 'create repository', CreateRepositoryCommand subcommand 'repositories:delete', 'delete repository', DeleteRepositoryCommand subcommand 'receive', 'receive what is pushed into the repository', ReceiveCommand subcommand 'deploy', 'deploy to spass', DeployCommand end end