Removed deprecated command line options.

This commit is contained in:
Chris Eppstein 2010-12-10 09:34:36 -08:00
parent e22acfde1e
commit 38e13e55e6
11 changed files with 70 additions and 25 deletions

View File

@ -22,8 +22,7 @@ fallback_load_path(File.join(File.dirname(__FILE__), '..', 'lib')) do
end end
runner = Proc.new do runner = Proc.new do
command_line_class = Compass::Exec::Helpers.select_appropriate_command_line_ui(ARGV) Compass::Exec::SubCommandUI.new(ARGV).run!
command_line_class.new(ARGV).run!
end end
if ARGV.delete("--profile") if ARGV.delete("--profile")

View File

@ -20,6 +20,7 @@ The Documentation for the [latest preview release](http://beta.compass-style.org
* Add a `--time` option to the compile and watch commands. This will print out * Add a `--time` option to the compile and watch commands. This will print out
the time spent compiling each sass file and a total at the end. the time spent compiling each sass file and a total at the end.
* Upgrade FSSM, the internal library that monitors the filesystem events for compass. * Upgrade FSSM, the internal library that monitors the filesystem events for compass.
* Removed the command line options that were deprecated in v0.10.
0.11.alpha.3 (12/05/2010) 0.11.alpha.3 (12/05/2010)
------------------------- -------------------------

View File

@ -3,7 +3,7 @@ end
require 'compass/commands/registry' require 'compass/commands/registry'
%w(base generate_grid_background help list_frameworks project_base %w(base generate_grid_background default help list_frameworks project_base
update_project watch_project create_project imports installer_command update_project watch_project create_project imports installer_command
print_version project_stats stamp_pattern sprite validate_project print_version project_stats stamp_pattern sprite validate_project
write_configuration interactive unpack_extension).each do |lib| write_configuration interactive unpack_extension).each do |lib|

View File

@ -0,0 +1,50 @@
module Compass
module Commands
module DefaultOptionsParser
def set_options(opts)
opts.on("--trace") do
self.options[:trace] = true
end
opts.on("-?", "-h", "--help") do
self.options[:command] = Proc.new do
Help.new(working_path, options.merge(:help_command => "help"))
end
end
opts.on("-q", "--quiet") do
self.options[:quiet] = true
end
opts.on("-v", "--version") do
self.options[:command] = Proc.new do
PrintVersion.new(working_path, options)
end
end
super
end
end
class Default < Base
class << self
def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments)
parser.extend(DefaultOptionsParser)
end
# def usage
# $stderr.puts caller.join("\n")
# "XXX"
# end
def parse!(arguments)
parser = option_parser(arguments)
parser.parse!
parser.options[:command] ||= Proc.new do
Help.new(working_path, options.merge(:help_command => "help"))
end
parser.options
end
end
def execute
instance_eval(&options[:command]).execute
end
end
end
end

View File

@ -5,6 +5,7 @@ module Compass::Commands
@commands[name.to_sym] = command_class @commands[name.to_sym] = command_class
end end
def get(name) def get(name)
return unless name
@commands ||= Hash.new @commands ||= Hash.new
@commands[name.to_sym] || @commands[abbreviation_of(name)] @commands[name.to_sym] || @commands[abbreviation_of(name)]
end end
@ -13,6 +14,8 @@ module Compass::Commands
matching = @commands.keys.select{|k| k.to_s =~ re} matching = @commands.keys.select{|k| k.to_s =~ re}
if matching.size == 1 if matching.size == 1
matching.first matching.first
elsif name =~ /^-/
nil
else else
raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}" raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}"
end end

View File

@ -16,7 +16,7 @@ end
module Compass::Exec module Compass::Exec
end end
%w(helpers switch_ui sub_command_ui %w(helpers sub_command_ui
global_options_parser project_options_parser global_options_parser project_options_parser
command_option_parser).each do |lib| command_option_parser).each do |lib|
require "compass/exec/#{lib}" require "compass/exec/#{lib}"

View File

@ -1,18 +1,6 @@
module Compass::Exec module Compass::Exec
module Helpers module Helpers
extend self extend self
def select_appropriate_command_line_ui(arguments)
if Compass::Commands.command_exists? arguments.first
SubCommandUI
else
unless arguments.include?("-h") || arguments.include?("--help")
Compass::Logger.new.red do
Compass::Util.compass_warn "WARNING: This interface is deprecated. Please use the new subcommand interface.\nSee `compass help` for more information.\n"
end
end
SwitchUI
end
end
def report_error(e, options) def report_error(e, options)
$stderr.puts "#{e.class} on line #{get_line e} of #{get_file e}: #{e.message}" $stderr.puts "#{e.class} on line #{get_line e} of #{get_file e}: #{e.message}"
if options[:trace] if options[:trace]

View File

@ -30,6 +30,11 @@ module Compass::Exec
def perform! def perform!
$command = args.shift $command = args.shift
command_class = Compass::Commands[$command] command_class = Compass::Commands[$command]
unless command_class
args.unshift($command)
$command = "help"
command_class = Compass::Commands::Default
end
@options = if command_class.respond_to?("parse_#{$command}!") @options = if command_class.respond_to?("parse_#{$command}!")
command_class.send("parse_#{$command}!", args) command_class.send("parse_#{$command}!", args)
else else
@ -38,7 +43,7 @@ module Compass::Exec
command_class.new(Dir.getwd, @options).execute command_class.new(Dir.getwd, @options).execute
rescue OptionParser::ParseError => e rescue OptionParser::ParseError => e
puts "Error: #{e.message}" puts "Error: #{e.message}"
puts command_class.usage puts command_class.usage if command_class.respond_to?(:usage)
end end
end end

View File

@ -107,8 +107,7 @@ module Compass::CommandLineHelper
end end
def execute(*arguments) def execute(*arguments)
command_line_class = Compass::Exec::Helpers.select_appropriate_command_line_ui(arguments) exit_code = Compass::Exec::SubCommandUI.new(arguments).run!
exit_code = command_line_class.new(arguments).run!
# fail "Command Failed with exit code: #{exit_code}" unless exit_code == 0 # fail "Command Failed with exit code: #{exit_code}" unless exit_code == 0
exit_code exit_code
end end

View File

@ -20,7 +20,7 @@ class CommandLineTest < Test::Unit::TestCase
def test_basic_install def test_basic_install
within_tmp_directory do within_tmp_directory do
compass "--boring", "basic" compass "create", "--boring", "basic"
assert File.exists?("basic/sass/screen.scss") assert File.exists?("basic/sass/screen.scss")
assert File.exists?("basic/stylesheets/screen.css") assert File.exists?("basic/stylesheets/screen.css")
assert_action_performed :directory, "basic/" assert_action_performed :directory, "basic/"
@ -33,7 +33,7 @@ class CommandLineTest < Test::Unit::TestCase
next if framework.name =~ /^_/ next if framework.name =~ /^_/
define_method "test_#{framework.name}_installation" do define_method "test_#{framework.name}_installation" do
within_tmp_directory do within_tmp_directory do
compass *%W(--boring --framework #{framework.name} #{framework.name}_project) compass *%W(create --boring --using #{framework.name} #{framework.name}_project)
assert File.exists?("#{framework.name}_project/sass/screen.scss"), "sass/screen.scss is missing. Found: #{Dir.glob("#{framework.name}_project/**/*").join(", ")}" assert File.exists?("#{framework.name}_project/sass/screen.scss"), "sass/screen.scss is missing. Found: #{Dir.glob("#{framework.name}_project/**/*").join(", ")}"
assert File.exists?("#{framework.name}_project/stylesheets/screen.css") assert File.exists?("#{framework.name}_project/stylesheets/screen.css")
assert_action_performed :directory, "#{framework.name}_project/" assert_action_performed :directory, "#{framework.name}_project/"
@ -45,13 +45,13 @@ class CommandLineTest < Test::Unit::TestCase
def test_basic_update def test_basic_update
within_tmp_directory do within_tmp_directory do
compass "--boring", "basic" compass "create", "--boring", "basic"
Dir.chdir "basic" do Dir.chdir "basic" do
# basic update with timestamp caching # basic update with timestamp caching
compass "--boring" compass "compile", "--boring"
assert_action_performed :unchanged, "sass/screen.scss" assert_action_performed :unchanged, "sass/screen.scss"
# basic update with force option set # basic update with force option set
compass "--force", "--boring" compass "compile", "--force", "--boring"
assert_action_performed :identical, "stylesheets/screen.css" assert_action_performed :identical, "stylesheets/screen.css"
end end
end end

View File

@ -39,7 +39,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
within_tmp_directory do within_tmp_directory do
generate_rails_app_directories("compass_rails") generate_rails_app_directories("compass_rails")
Dir.chdir "compass_rails" do Dir.chdir "compass_rails" do
compass(*%w(--rails --trace --boring --sass-dir app/stylesheets --css-dir public/stylesheets/compiled .)) compass(*%w(init rails --trace --boring --sass-dir app/stylesheets --css-dir public/stylesheets/compiled .))
assert_action_performed :create, "./app/stylesheets/screen.scss" assert_action_performed :create, "./app/stylesheets/screen.scss"
assert_action_performed :create, "./config/initializers/compass.rb" assert_action_performed :create, "./config/initializers/compass.rb"
end end