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
Start sinatra app.
Instance Method Details
#add!(dir, name = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bananajour/commands.rb', line 39 def add!(dir, name = nil) dir = Pathname(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.exist? 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
35 36 37 |
# File 'lib/bananajour/commands.rb', line 35 def advertise! fork { Bananajour::Bonjour::Advertiser.new.go! } end |
#check_git! ⇒ Object
6 7 8 9 10 |
# File 'lib/bananajour/commands.rb', line 6 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
12 13 14 15 16 |
# File 'lib/bananajour/commands.rb', line 12 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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bananajour/commands.rb', line 74 def clone!(url, clone_name) dir = clone_name || File.basename(url).chomp('.git') if File.exist?(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
66 67 68 |
# File 'lib/bananajour/commands.rb', line 66 def (repo_dirname) (repo_dirname).gsub("git push banana master", "git push banana master".foreground(:yellow)) end |
#plain_init_success_message(repo_dirname) ⇒ Object
70 71 72 |
# File 'lib/bananajour/commands.rb', line 70 def (repo_dirname) "Bananajour repository #{repo_dirname} initialised and remote banana added.\nNext: git push banana master" end |
#serve_git! ⇒ Object
30 31 32 33 |
# File 'lib/bananajour/commands.rb', line 30 def serve_git! puts "* Starting " + "#{git_uri}".foreground(:yellow) fork { exec "git daemon --base-path=#{repositories_path} --export-all" } end |
#serve_web! ⇒ Object
Start sinatra app.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bananajour/commands.rb', line 19 def serve_web! puts "* Starting " + web_uri.foreground(:yellow) fork do ENV["RACK_ENV"] ||= "production" require "bananajour/../../sinatra/app" Sinatra::Application.set :port, web_port Sinatra::Application.set :server, "thin" Sinatra::Application.run! end end |