Skip to content

Commit

Permalink
refactor to a command class
Browse files Browse the repository at this point in the history
  • Loading branch information
SaitoWu committed Apr 7, 2014
1 parent e213b14 commit 196a70d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
3 changes: 1 addition & 2 deletions bin/simba
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + "/../lib/simba"
arguments = ARGV.any? ? ARGV : ['-h']
Simba::SkeletonGenerator.start(arguments)
Simba::Command.start
41 changes: 2 additions & 39 deletions lib/simba.rb
@@ -1,42 +1,5 @@
require "thor"
require "thor/group"
require "securerandom"
require_relative "simba/version"
require "simba/command"
require "simba/version"

module Simba
class SkeletonGenerator < Thor::Group
include Thor::Actions

def self.source_root
File.dirname(__FILE__)
end

def self.banner
"simba [app_name]"
end

desc "Description:\n\n\tsimba is a generator for sinatra applications."

argument :name, :desc => "The name of your sinatra app"
class_option :skip_bundle,
:default => false,
:type => :boolean,
:desc => "Skip bundle install when creating app skeleton"

def setup_skeleton
self.destination_root = name
@class_name = name
@session_secret = SecureRandom.hex 16
directory("../template/", self.destination_root)
end

def bundle_dependencies
unless options[:skip_bundle]
say "Bundling application dependencies using bundler."
in_root do
run 'bundle install'
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/simba/command.rb
@@ -0,0 +1,22 @@
require "thor"

module Simba
class Command < Thor
include Thor::Actions
map "-v" => :version

def self.source_root
File.dirname(__FILE__)
end

desc "version", "show version"
def version
puts Simba::VERSION
end

desc "new", "create the skeleton of project"
def new(name)
directory('templates', name)
end
end
end

0 comments on commit 196a70d

Please sign in to comment.