diff --git a/lib/compass/commands/create_project.rb b/lib/compass/commands/create_project.rb index bf764f52..2c2dba6f 100644 --- a/lib/compass/commands/create_project.rb +++ b/lib/compass/commands/create_project.rb @@ -6,12 +6,28 @@ module Compass module CreateProjectOptionsParser def set_options(opts) - opts.banner = %q{ - Usage: compass create path/to/project [options] + if $command == "create" + opts.banner = %Q{ + Usage: compass create path/to/project [options] - Description: - Create a new compass project at the path specified. - }.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n") + Description: + Create a new compass project at the path specified. + + Options: + }.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n") + else + opts.banner = %Q{ + Usage: compass init project_type path/to/project [options] + + Description: + Initialize an existing project at the path specified. + + Supported Project Types: + * rails + + Options: + }.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n").strip + end opts.on("--using FRAMEWORK", "Framework to use when creating the project.") do |framework| framework = framework.split('/', 2) @@ -29,15 +45,28 @@ module Compass register :init class << self + def option_parser(arguments) + parser = Compass::Exec::CommandOptionParser.new(arguments) + parser.extend(Compass::Exec::GlobalOptionsParser) + parser.extend(Compass::Exec::ProjectOptionsParser) + parser.extend(CreateProjectOptionsParser) + end + + def usage + option_parser([]).to_s + end + def parse!(arguments) - parser = parse_options!(arguments) + parser = option_parser(arguments) + parse_options!(parser, arguments) parse_arguments!(parser, arguments) set_default_arguments(parser) parser.options end def parse_init!(arguments) - parser = parse_options!(arguments) + parser = option_parser(arguments) + parse_options!(parser, arguments) if arguments.size > 0 parser.options[:project_type] = arguments.shift.to_sym end @@ -46,11 +75,7 @@ module Compass parser.options end - def parse_options!(arguments) - parser = Compass::Exec::CommandOptionParser.new(arguments) - parser.extend(Compass::Exec::GlobalOptionsParser) - parser.extend(Compass::Exec::ProjectOptionsParser) - parser.extend(CreateProjectOptionsParser) + def parse_options!(parser, arguments) parser.parse! parser end diff --git a/lib/compass/exec/command_option_parser.rb b/lib/compass/exec/command_option_parser.rb index 2bd599cc..3e1a7b43 100644 --- a/lib/compass/exec/command_option_parser.rb +++ b/lib/compass/exec/command_option_parser.rb @@ -1,16 +1,21 @@ module Compass::Exec class CommandOptionParser - attr_accessor :options, :arguments + attr_accessor :options, :arguments, :opts def initialize(arguments) self.arguments = arguments self.options = {} end def parse! - opts = OptionParser.new(&method(:set_options)) opts.parse!(arguments) end + def opts + OptionParser.new(&method(:set_options)) + end def set_options(opts) end + def to_s + opts.to_s + end end end diff --git a/lib/compass/exec/sub_command_ui.rb b/lib/compass/exec/sub_command_ui.rb index 867514ab..e7b33260 100644 --- a/lib/compass/exec/sub_command_ui.rb +++ b/lib/compass/exec/sub_command_ui.rb @@ -28,14 +28,17 @@ module Compass::Exec protected def perform! - command = args.shift - command_class = Compass::Commands[command] - options = if command_class.respond_to?("parse_#{command}!") - command_class.send("parse_#{command}!", args) + $command = args.shift + command_class = Compass::Commands[$command] + options = if command_class.respond_to?("parse_#{$command}!") + command_class.send("parse_#{$command}!", args) else command_class.parse!(args) end command_class.new(Dir.getwd, options).execute + rescue OptionParser::ParseError => e + puts "Error: #{e.message}" + puts command_class.usage end end