#!/usr/bin/env ruby require 'fileutils' require 'optparse' require 'methadone' require 'methadone/cli' include FileUtils include Methadone::Main include Methadone::CLILogging include Methadone::CLI include Methadone::SH main do |app_name| check_and_prepare_basedir!(app_name,options[:force]) using_readme = options[:readme] gemname = File.basename(app_name) module_name = gemname.split(/_/).map(&:capitalize).join('') debug "Creating project for gem #{gemname}" chdir File.dirname(app_name) sh! "bundle gem #{gemname}" chdir gemname template_dirs_in(:full).each { |dir| mkdir_p dir } ["Rakefile", ".gitignore", "test/tc_something.rb", "features/support/env.rb"].each do |file| copy_file file, :binding => binding end license = options[:license] warn "warning: your app has no license" unless license license = nil if license == 'NONE' copy_file "#{options[:license]}_LICENSE.txt", :as => "LICENSE.txt" if license copy_file "README.rdoc", :binding => binding if using_readme copy_file "features/executable.feature", :as => "#{gemname}.feature", :binding => binding copy_file "features/step_definitions/executable_steps.rb", :as => "#{gemname}_steps.rb" copy_file "bin/executable", :as => gemname, :executable => true, :binding => binding gem_variable = File.open("#{gemname}.gemspec") { |x| x.read }.match(/(\w+)\.executables/)[1] add_to_file "#{gemname}.gemspec", [ " #{gem_variable}.add_development_dependency('rdoc')", " #{gem_variable}.add_development_dependency('aruba')", " #{gem_variable}.add_development_dependency('rake','~> 0.9.2')", " #{gem_variable}.add_dependency('methadone')", ], :before => /^end\s*$/ end options[:readme] = true description "Kick the bash habit by bootstrapping your Ruby command-line apps" on("--force","Overwrite files if they exist") on("--[no-]readme","[Do not ]produce a README file") licenses = %w(mit apache custom NONE) on("-l LICENSE","--license",licenses,"Specify the license for your project (#{licenses.join('|')})") use_log_level_option arg :app_name, :required version Methadone::VERSION defaults_from_env_var 'METHODONE_OPTS' go!