From 38e13e55e640cf6473f28dc3cf4357ad66e3ac4d Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 10 Dec 2010 09:34:36 -0800 Subject: [PATCH] Removed deprecated command line options. --- bin/compass | 3 +- doc-src/content/CHANGELOG.markdown | 1 + lib/compass/commands.rb | 2 +- lib/compass/commands/default.rb | 50 ++++++++++++++++++++++++++++++ lib/compass/commands/registry.rb | 3 ++ lib/compass/exec.rb | 2 +- lib/compass/exec/helpers.rb | 12 ------- lib/compass/exec/sub_command_ui.rb | 7 ++++- test/command_line_helper.rb | 3 +- test/command_line_test.rb | 10 +++--- test/rails_integration_test.rb | 2 +- 11 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 lib/compass/commands/default.rb diff --git a/bin/compass b/bin/compass index 094bd700..c174ce02 100755 --- a/bin/compass +++ b/bin/compass @@ -22,8 +22,7 @@ fallback_load_path(File.join(File.dirname(__FILE__), '..', 'lib')) do end runner = Proc.new do - command_line_class = Compass::Exec::Helpers.select_appropriate_command_line_ui(ARGV) - command_line_class.new(ARGV).run! + Compass::Exec::SubCommandUI.new(ARGV).run! end if ARGV.delete("--profile") diff --git a/doc-src/content/CHANGELOG.markdown b/doc-src/content/CHANGELOG.markdown index b51faea3..38de3be2 100644 --- a/doc-src/content/CHANGELOG.markdown +++ b/doc-src/content/CHANGELOG.markdown @@ -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 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. +* Removed the command line options that were deprecated in v0.10. 0.11.alpha.3 (12/05/2010) ------------------------- diff --git a/lib/compass/commands.rb b/lib/compass/commands.rb index 8896100d..f4230ef4 100644 --- a/lib/compass/commands.rb +++ b/lib/compass/commands.rb @@ -3,7 +3,7 @@ end 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 print_version project_stats stamp_pattern sprite validate_project write_configuration interactive unpack_extension).each do |lib| diff --git a/lib/compass/commands/default.rb b/lib/compass/commands/default.rb new file mode 100644 index 00000000..ab50a3be --- /dev/null +++ b/lib/compass/commands/default.rb @@ -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 diff --git a/lib/compass/commands/registry.rb b/lib/compass/commands/registry.rb index 767cc652..64372079 100644 --- a/lib/compass/commands/registry.rb +++ b/lib/compass/commands/registry.rb @@ -5,6 +5,7 @@ module Compass::Commands @commands[name.to_sym] = command_class end def get(name) + return unless name @commands ||= Hash.new @commands[name.to_sym] || @commands[abbreviation_of(name)] end @@ -13,6 +14,8 @@ module Compass::Commands matching = @commands.keys.select{|k| k.to_s =~ re} if matching.size == 1 matching.first + elsif name =~ /^-/ + nil else raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}" end diff --git a/lib/compass/exec.rb b/lib/compass/exec.rb index 0d49b8e7..872cbc01 100644 --- a/lib/compass/exec.rb +++ b/lib/compass/exec.rb @@ -16,7 +16,7 @@ end module Compass::Exec end -%w(helpers switch_ui sub_command_ui +%w(helpers sub_command_ui global_options_parser project_options_parser command_option_parser).each do |lib| require "compass/exec/#{lib}" diff --git a/lib/compass/exec/helpers.rb b/lib/compass/exec/helpers.rb index e0ba7e5e..5cf05a05 100644 --- a/lib/compass/exec/helpers.rb +++ b/lib/compass/exec/helpers.rb @@ -1,18 +1,6 @@ module Compass::Exec module Helpers 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) $stderr.puts "#{e.class} on line #{get_line e} of #{get_file e}: #{e.message}" if options[:trace] diff --git a/lib/compass/exec/sub_command_ui.rb b/lib/compass/exec/sub_command_ui.rb index 45ff9c84..972f82c8 100644 --- a/lib/compass/exec/sub_command_ui.rb +++ b/lib/compass/exec/sub_command_ui.rb @@ -30,6 +30,11 @@ module Compass::Exec def perform! $command = args.shift 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}!") command_class.send("parse_#{$command}!", args) else @@ -38,7 +43,7 @@ module Compass::Exec command_class.new(Dir.getwd, @options).execute rescue OptionParser::ParseError => e puts "Error: #{e.message}" - puts command_class.usage + puts command_class.usage if command_class.respond_to?(:usage) end end diff --git a/test/command_line_helper.rb b/test/command_line_helper.rb index b6b47825..c2b58cd9 100644 --- a/test/command_line_helper.rb +++ b/test/command_line_helper.rb @@ -107,8 +107,7 @@ module Compass::CommandLineHelper end def execute(*arguments) - command_line_class = Compass::Exec::Helpers.select_appropriate_command_line_ui(arguments) - exit_code = command_line_class.new(arguments).run! + exit_code = Compass::Exec::SubCommandUI.new(arguments).run! # fail "Command Failed with exit code: #{exit_code}" unless exit_code == 0 exit_code end diff --git a/test/command_line_test.rb b/test/command_line_test.rb index f81dceca..93ee388c 100644 --- a/test/command_line_test.rb +++ b/test/command_line_test.rb @@ -20,7 +20,7 @@ class CommandLineTest < Test::Unit::TestCase def test_basic_install within_tmp_directory do - compass "--boring", "basic" + compass "create", "--boring", "basic" assert File.exists?("basic/sass/screen.scss") assert File.exists?("basic/stylesheets/screen.css") assert_action_performed :directory, "basic/" @@ -33,7 +33,7 @@ class CommandLineTest < Test::Unit::TestCase next if framework.name =~ /^_/ define_method "test_#{framework.name}_installation" 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/stylesheets/screen.css") assert_action_performed :directory, "#{framework.name}_project/" @@ -45,13 +45,13 @@ class CommandLineTest < Test::Unit::TestCase def test_basic_update within_tmp_directory do - compass "--boring", "basic" + compass "create", "--boring", "basic" Dir.chdir "basic" do # basic update with timestamp caching - compass "--boring" + compass "compile", "--boring" assert_action_performed :unchanged, "sass/screen.scss" # basic update with force option set - compass "--force", "--boring" + compass "compile", "--force", "--boring" assert_action_performed :identical, "stylesheets/screen.css" end end diff --git a/test/rails_integration_test.rb b/test/rails_integration_test.rb index edf38abb..5e69ca9e 100644 --- a/test/rails_integration_test.rb +++ b/test/rails_integration_test.rb @@ -39,7 +39,7 @@ class RailsIntegrationTest < Test::Unit::TestCase within_tmp_directory do generate_rails_app_directories("compass_rails") 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, "./config/initializers/compass.rb" end