From 16fa1638801976bbcbd235fd5f5c114415c4b55e Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 11 Sep 2012 20:55:16 +0200 Subject: [PATCH] 'bootstar init' now creates an empty dir structure Ref. #5 --- bin/bootstar | 12 ++++------ bootstar.gemspec | 21 ++++++++++-------- lib/bootstar/cli.rb | 33 +++++++--------------------- spec/acceptance/app_creation_spec.rb | 29 ++++++++++++++++++++++++ spec/bootstar_spec.rb | 3 +-- spec/spec_helper.rb | 3 ++- 6 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 spec/acceptance/app_creation_spec.rb diff --git a/bin/bootstar b/bin/bootstar index d3796e1..7f2658b 100755 --- a/bin/bootstar +++ b/bin/bootstar @@ -1,10 +1,6 @@ #!/usr/bin/env ruby +require 'rubygems' # ruby1.9 doesn't "require" it though +require 'thor' +require 'bootstar/cli' -require 'bootstar' - -begin - Bootstar::CLI.new *ARGV.dup -rescue StandardError => e - puts "Error: #{e.message}" - puts e.backtrace -end \ No newline at end of file +Bootstar::CLI.start diff --git a/bootstar.gemspec b/bootstar.gemspec index ea1e27c..23d630e 100644 --- a/bootstar.gemspec +++ b/bootstar.gemspec @@ -1,24 +1,27 @@ # -*- encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "bootstar/version" +$:.push File.expand_path('../lib', __FILE__) +require 'bootstar/version' Gem::Specification.new do |s| - s.name = "bootstar" + s.name = 'bootstar' s.version = Bootstar::VERSION - s.authors = ["Giovanni Cappellotto"] - s.email = ["potomak84@gmail.com"] - s.homepage = "http://github.com/hackatron/bootstar" + s.authors = ['Nicola Brisotto', 'Giovanni Cappellotto', 'Matteo Centenaro', 'Eugenio Depalo', 'Matteo Depalo', 'Francesco Tartaggia'] + s.email = ['nicolabrisotto@gmail.com', 'potomak84@gmail.com', 'bugant@gmail.com', 'eugeniodepalo@gmail.com', 'matteodepalo@gmail.com', 'francesco.tartaggia@gmail.com'] + s.homepage = 'http://github.com/hackatron/bootstar' s.summary = %q{A tool to bootstrap your service oriented app} s.description = %q{Bootstar is a tool to bootstrap your service oriented app.} - s.rubyforge_project = "bootstar" + s.rubyforge_project = 'bootstar' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + s.require_paths = ['lib'] + + s.add_dependency 'thor' # specify any dependencies here; for example: - s.add_development_dependency "rspec" + s.add_development_dependency 'rspec' + s.add_development_dependency 'debugger' # s.add_runtime_dependency "rest-client" end diff --git a/lib/bootstar/cli.rb b/lib/bootstar/cli.rb index 95dec16..08b908b 100644 --- a/lib/bootstar/cli.rb +++ b/lib/bootstar/cli.rb @@ -1,29 +1,12 @@ -require 'optparse' +require 'thor' module Bootstar - class CLI - - attr_accessor :params, :action - - def initialize(*args) - @params = {} - @action = :output - - OptionParser.new do |opts| - opts.banner = "Usage: bootstar new" - - opts.on_tail("-h", "--help", "Show this message") do - puts opts - exit - end - - if args.empty? - puts opts - exit - end - end.parse!(args) - - puts "Bootstar executable..." + class CLI < Thor + desc 'init APP_NAME', 'Create a new basic bootstar app' + def init(name) + Dir.mkdir(File.join('.', name)) + Dir.chdir(File.join('.', name)) + ['api', 'client', 'ruby'].each {|dir| Dir.mkdir(File.join('.', "#{name}-#{dir}"))} end end -end \ No newline at end of file +end diff --git a/spec/acceptance/app_creation_spec.rb b/spec/acceptance/app_creation_spec.rb new file mode 100644 index 0000000..c12b9e2 --- /dev/null +++ b/spec/acceptance/app_creation_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe 'App creation' do + context 'bootstar init' do + before(:all) do + system('bootstar init test-app') + end + + after(:all) do + system('rm -rf test-app') + end + + it 'should create folder with the app name' do + File.directory?('./test-app').should be_true + end + + it 'should create a directory for the API' do + File.directory?('./test-app/test-app-api').should be_true + end + + it 'should create a directory for the client' do + File.directory?('./test-app/test-app-client').should be_true + end + + it 'should create a directory for the API wrapper gem' do + File.directory?('./test-app/test-app-ruby').should be_true + end + end +end diff --git a/spec/bootstar_spec.rb b/spec/bootstar_spec.rb index 2346eb7..dbb4fca 100644 --- a/spec/bootstar_spec.rb +++ b/spec/bootstar_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' describe Bootstar do - pending "write it" -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 411b371..22e256f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,8 @@ require 'rubygems' require 'bundler/setup' -require 'bootstar' +# require 'bootstar' +require 'debugger' RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true