#!/usr/bin/env ruby ## # A fancy wrapper around 'rails' that creates a BrowserCMS project. # require File.join(File.dirname(__FILE__), "..", 'lib/command_line') require 'optparse' ARGV << "-h" if ARGV.empty? # Using optsparse primarily for help messages, since most options just get passed directly to rails. options = {} ARGV.clone.options do |opts| opts.banner = "Usage: browsercms /path/to/your/cms/project [options]" # While Rails supports more databases, BrowserCMS has really only been tested against the following: opts.on("-d", "--database=name", String, "Preconfigure for selected database (options: mysql/postgresql/sqlite3)", "Default: sqlite3") opts.on("-m", "--template=path", String, "BrowserCMS application type to create (options: module, demo)", "Default: blank") opts.separator(" ") opts.separator("BrowserCMS Info:") opts.on("-h", "--help", String, "Show this help message and quit.") { puts opts; exit } opts.on("-v", "--version", String, "Shows the rails version number and quit.") { system("rails -v"); exit } # These are copy&paste from the 'rails' options. Repeated here because I'm not sure its possible to reuse their options automatically. opts.separator(" ") opts.separator("Rails Options:") opts.on("-r", "--ruby=path", String, "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).", "Default: /usr/local/bin/ruby") opts.on("-D", "--with-dispatchers", "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton", "Default: false") opts.on("-f", "--freeze", "Freeze Rails in vendor/rails from the gems generating the skeleton.", "Default: false") opts.on("-p", "--pretend", "Run but do not make any changes.") opts.on("--force", "--force", "Overwrite files that already exist.") opts.on("-s", "--skip", "Skip files that already exist.") opts.on("-q", "--quiet", "Suppress normal output.") opts.on("-t", "--backtrace", "Debugging: show backtrace on errors.") opts.on("-c", "--svn", "Modify files with subversion. (Note: svn must be in path)") opts.on("-g", "--git", "Modify files with git. (Note: git must be in path)") opts.separator(" ") opts.separator("Description:") opts.separator(" The 'browsercms' command creates a new BrowserCMS application with a default directory structure ") opts.separator(" and configuration at the path you specify. It will create and migrate the database with the schema") opts.separator(" and seed data.") opts.separator(" ") opts.separator("Example:") opts.separator(" browsercms ~/projects/website_name") opts.separator(" This generates a blank BrowserCMS project. Suitable for starting a new website project.") opts.separator(" ") opts.separator(" browsercms website_name -m demo") opts.separator(" Generates a BrowserCMS application with a sample demo website. Suitable for learning BrowserCMS.") opts.separator(" ") opts.separator(" browsercms bcms_my_module -m module") opts.separator(" Generates a BrowserCMS module. Used to create code that can be shared between BrowserCMS projects.") opts.separator(" (Note: Module name MUST start with 'bcms_'.)") opts.parse! end # Replace short hand versions of the templates with the absolute path on the local machine. CommandLine.set_template(ARGV) command = (RUBY_PLATFORM =~ /mswin32/ ? "cmd /c " : "") command += "rails #{ARGV.join(" ")}" success = system(command) project_name = ARGV[0] if (success) puts "\nCreated new BrowserCMS project '#{project_name}'." puts " To get started, type 'cd #{project_name}'" puts " then 'ruby script/server' and open your browser to 'http://localhost:3000'." else puts "\n Unable to create BrowserCMS project '#{project_name}'." end