#!/usr/bin/env ruby require "rubygems" require "cmdparse" cmd = CmdParse::CommandParser.new(true) cmd.program_name = "lipsiahosting" cmd.program_version = [1, 0, 1] cmd.add_command(CmdParse::HelpCommand.new) cmd.add_command(CmdParse::VersionCommand.new) # lipsiahosting init init = CmdParse::Command.new("init", false) init.short_desc = "Init a new repository for the given user, ex: lipsiahosting init d.dagostino." init.options = CmdParse::OptionParserWrapper.new do |opt| opt.on( '-i', '--ignore DIRECTORIES', 'Set folder/file to ignore split it by "," ex: "some/folder/*,another/folder/**/*"' ) { |value| $ignores = value } end init.set_execution_block do |args| user = args[0] if !user init.show_help exit 1 end ignores = $ignores.split(",") rescue [] puts "-> Your username is: #{user}" puts "Removing *.svn folders" system "find . -name .svn -print0 | xargs -0 rm -rf" puts "Removing *.git folders" system "find . -name .git -print0 | xargs -0 rm -rf" puts "Removeing .gitignore" system "rm -rf .gitignore" puts "Initialize the new repository ... DONE" system "git init" path = File.expand_path(".") project = File.basename(path) puts "-> Your current project is: #{project.downcase}" puts "Adding 'log/*' to .gitignore file" system "echo 'log/*'>> .gitignore" puts "Adding 'tmp/*' to .gitignore file" system "echo 'tmp/*'>> .gitignore" puts "Adding '.DS_Store' to .gitignore file" system "echo '.DS_Store'>> .gitignore" puts "Adding 'public/cache/**/*' to .gitignore file" system "echo 'public/cache/**/*'>> .gitignore" if ignores for folder in ignores puts "Adding '#{folder}' to .gitignore file" system "echo '#{folder}'>> .gitignore" end end system "git add .gitignore" puts "Committing application locally" system "git add *" system 'git commit -a -m "initial import of site" > /dev/null' system "git remote add origin git@server1.lipsiasoft.com:#{user}/#{project}.git" puts "Pushing application to the remote server. The name of the branch is:" system "git remote" system "git push origin master" end cmd.add_command(init) cmd.parse