Module: Bananajour::Commands
- Included in:
- Bananajour
- Defined in:
- lib/bananajour/commands.rb
Instance Method Summary collapse
- #add!(dir, name = nil) ⇒ Object
- #advertise! ⇒ Object
- #check_git! ⇒ Object
- #check_git_config! ⇒ Object
- #clone!(url, clone_name) ⇒ Object
- #init_success_message(repo_dirname) ⇒ Object
- #plain_init_success_message(repo_dirname) ⇒ Object
- #serve_git! ⇒ Object
- #serve_web! ⇒ Object
Instance Method Details
#add!(dir, name = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bananajour/commands.rb', line 29 def add!(dir, name = nil) dir = Fancypath(dir) unless dir.join(".git").directory? abort "Can't init project #{dir}, no .git directory found." end if name.nil? default_name = dir.basename.to_s print "Project Name?".foreground(:yellow) + " [#{default_name}] " name = (STDIN.gets || "").strip name = default_name if name.empty? end repo = Bananajour::Repository.for_name(name) if repo.exists? abort "You've already a project #{repo}." end repo.init! Dir.chdir(dir) { `git remote add banana #{repo.path.}` } puts (repo.dirname) repo end |
#advertise! ⇒ Object
25 26 27 |
# File 'lib/bananajour/commands.rb', line 25 def advertise! fork { Bananajour::Bonjour::Advertiser.new.go! } end |
#check_git! ⇒ Object
3 4 5 6 7 |
# File 'lib/bananajour/commands.rb', line 3 def check_git! if (version = `git --version`.strip) =~ /git version 1\.[12345]/ abort "You have #{version}, you need at least 1.6" end end |
#check_git_config! ⇒ Object
9 10 11 12 13 |
# File 'lib/bananajour/commands.rb', line 9 def check_git_config! = lambda {|key, example| "You haven't set your #{key} in your git config yet. To set it: git config --global #{key} '#{example}'"} abort(["user.name", "My Name"]) if config.name.empty? abort(["user.email", "[email protected]"]) if config.email.empty? end |
#clone!(url, clone_name) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bananajour/commands.rb', line 64 def clone!(url, clone_name) dir = clone_name || File.basename(url).chomp('.git') if File.exists?(dir) abort "Can't clone #{url} to #{dir}, the directory already exists." end `git clone #{url} #{dir}` if $? != 0 abort "Failed to clone bananajour repository #{url} to #{dir}." else puts "Bananajour repository #{url} cloned to #{dir}." add!(dir, dir) end end |
#init_success_message(repo_dirname) ⇒ Object
56 57 58 |
# File 'lib/bananajour/commands.rb', line 56 def (repo_dirname) (repo_dirname).gsub("git push banana master", "git push banana master".foreground(:yellow)) end |
#plain_init_success_message(repo_dirname) ⇒ Object
60 61 62 |
# File 'lib/bananajour/commands.rb', line 60 def (repo_dirname) "Bananajour repository #{repo_dirname} initialised and remote banana added.\nNext: git push banana master" end |
#serve_git! ⇒ Object
20 21 22 23 |
# File 'lib/bananajour/commands.rb', line 20 def serve_git! fork { exec "git daemon --base-path=#{repositories_path} --export-all" } puts "* Started " + "#{git_uri}".foreground(:yellow) end |
#serve_web! ⇒ Object
15 16 17 18 |
# File 'lib/bananajour/commands.rb', line 15 def serve_web! fork { exec "/usr/bin/env ruby #{File.dirname(__FILE__)}/../../sinatra/app.rb -p #{web_port} -e production" } puts "* Started " + web_uri.foreground(:yellow) end |