From 43ee4e1c98b6ca15483be5bee0743e857e7c2e4c Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 20 Feb 2009 17:12:36 -0800 Subject: [PATCH] Added a new command line option to emit and update the stand-alone configuration file. --- lib/compass/commands/write_configuration.rb | 37 +++++++++++++++++++++ lib/compass/exec.rb | 4 +++ 2 files changed, 41 insertions(+) create mode 100644 lib/compass/commands/write_configuration.rb diff --git a/lib/compass/commands/write_configuration.rb b/lib/compass/commands/write_configuration.rb new file mode 100644 index 00000000..04bbc2e4 --- /dev/null +++ b/lib/compass/commands/write_configuration.rb @@ -0,0 +1,37 @@ +require File.join(File.dirname(__FILE__), 'project_base') + +module Compass + module Commands + class WriteConfiguration < ProjectBase + + def initialize(working_path, options) + super + assert_project_directory_exists! + end + + def perform + read_project_configuration + Compass.configuration.set_maybe(options) + Compass.configuration.set_defaults! + config_file = projectize("config.rb") + if File.exists?(config_file) + if options[:force] + logger.record(:overwrite, config_file) + else + message = "#{config_file} already exists. Run with --force to overwrite." + raise Compass::FilesystemConflict.new(message) + end + else + logger.record(:create, basename(config_file)) + end + project_path, Compass.configuration.project_path = Compass.configuration.project_path, nil + open(config_file,'w') do |config| + config.puts Compass.configuration.serialize + end + Compass.configuration.project_path = project_path + end + + + end + end +end \ No newline at end of file diff --git a/lib/compass/exec.rb b/lib/compass/exec.rb index d38b7d50..1b073a36 100644 --- a/lib/compass/exec.rb +++ b/lib/compass/exec.rb @@ -113,6 +113,10 @@ END self.options[:command] = :list_frameworks end + opts.on('-c', '--write-configuration', "Write the current configuration to the configuration file.") do + self.options[:command] = :write_configuration + end + opts.on('-f FRAMEWORK', '--framework FRAMEWORK', 'Set up a new project using the specified framework.') do |framework| self.options[:framework] = framework end