Permalink
Browse files

Stub app creation

  • Loading branch information...
agnoster committed Nov 17, 2012
1 parent 7cf1894 commit 5c3c7f57d869f58df4653c6744e6da57570d111c
Showing with 92 additions and 2 deletions.
  1. +0 −2 Gemfile
  2. +7 −0 bin/hoboku
  3. +2 −0 hoboku.gemspec
  4. +2 −0 lib/hoboku.rb
  5. +42 −0 lib/hoboku/app.rb
  6. +30 −0 lib/hoboku/cli.rb
  7. +9 −0 lib/hoboku/params.rb
View
@@ -1,4 +1,2 @@
source 'https://rubygems.org'
-
-# Specify your gem's dependencies in hoboku.gemspec
gemspec
View
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+#vim:ft=ruby
+
+require 'hoboku/cli'
+
+$PROGRAM_NAME = File.basename(__FILE__)
+Hoboku::CLI.start
View
@@ -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
View
@@ -1,4 +1,6 @@
require "hoboku/version"
+require "hoboku/cli"
+require "hoboku/app"
module Hoboku
# Your code goes here...
View
@@ -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
View
@@ -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
View
@@ -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.