Skip to content

Commit

Permalink
Stub app creation
Browse files Browse the repository at this point in the history
  • Loading branch information
agnoster committed Nov 17, 2012
1 parent 7cf1894 commit 5c3c7f5
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Gemfile
@@ -1,4 +1,2 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in hoboku.gemspec
gemspec
7 changes: 7 additions & 0 deletions bin/hoboku
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
#vim:ft=ruby

require 'hoboku/cli'

$PROGRAM_NAME = File.basename(__FILE__)
Hoboku::CLI.start
2 changes: 2 additions & 0 deletions hoboku.gemspec
Expand Up @@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_runtime_dependency('thor', ['>= 0.16.0'])
end
2 changes: 2 additions & 0 deletions lib/hoboku.rb
@@ -1,4 +1,6 @@
require "hoboku/version"
require "hoboku/cli"
require "hoboku/app"

module Hoboku
# Your code goes here...
Expand Down
42 changes: 42 additions & 0 deletions lib/hoboku/app.rb
@@ -0,0 +1,42 @@
module Hoboku
class App
attr_accessor :dir, :name

def initialize(app_name=nil)
@name = app_name || File.basename(dir)
end

def create
print "Creating #{name}... "
# create the app here
puts "done"
puts http_uri + ' | ' + git_uri
add_remote
end

def hostname
name + '.localhost'
end

def http_uri
"http://#{hostname}/"
end

def git_uri
".hoboku/#{name}.git"
end

def browse
system "open", http_uri
end

def add_remote
# add git remote
puts "Git remote hoboku added"
end

def dir
@dir ||= `git rev-parse --show-toplevel 2>/dev/null || pwd`.chomp
end
end
end
30 changes: 30 additions & 0 deletions lib/hoboku/cli.rb
@@ -0,0 +1,30 @@
require 'thor'
require 'hoboku/params'
require 'hoboku/app'

module Hoboku
class CLI < Thor
class_option :app, desc: "Name of the hoboku application", aliases: '-a'

desc "create [APP_NAME]", "Create the hoboku app"
def create(app_name=nil)
params.app ||= app_name
app.create
end

desc "browse", "Open the app in the browser"
def browse
app.browse
end

protected

def params
@params ||= Params.new(options)
end

def app
@app ||= App.new(params.app)
end
end
end
9 changes: 9 additions & 0 deletions lib/hoboku/params.rb
@@ -0,0 +1,9 @@
require 'ostruct'

module Hoboku
class Params < OpenStruct
def app
@table[:app] ||= ENV['APP_NAME']
end
end
end

0 comments on commit 5c3c7f5

Please sign in to comment.