lib/caramelize/cli/create_command.rb in caramelize-0.0.3 vs lib/caramelize/cli/create_command.rb in caramelize-0.1.0
- old
+ new
@@ -1,55 +1,50 @@
#Encoding: UTF-8
-
require 'caramelize/cli'
module Caramelize::CLI
# The CLI command for creating a caramelize config file.
class CreateCommand < CmdParse::Command
+ # The website config-file. Default: the current working directory.
+ attr_reader :config_file
+
def initialize #:nodoc:
super('create', false)
- #self.description = Utils.format("If the verbosity level is set to verbose, the created files are listed.")
+ self.description = "If the verbosity level is set to verbose, the created files are listed."
self.short_desc = 'Create a default config file for caramelize'
self.options = CmdParse::OptionParserWrapper.new do |opts|
opts.separator "Arguments:"
- opts.separator opts.summary_indent + "DIR: the directory in which the website should be created"
+ opts.on("--config <file>", "-f", String, "The config file (default: caramel.rb)") {|p| @config_file = p}
end
end
def usage # :nodoc:
- "Usage: #{commandparser.program_name} [global options] create [options] DIR"
+ "Usage: #{commandparser.program_name} [global options] create [options]"
end
- # Create a caramelize config file in the directory <tt>args[0]</tt>.
+ # Create a caramelize config file.
def execute(args)
- if args.length == 0
- raise OptionParser::MissingArgument.new('DIR')
- else
- begin
-
- # TODO create dummy config file
-
- puts "Created new configuration file: caramelize.rb"
- #puts args[0]
- require 'fileutils'
-
- FileUtils.cp(File.dirname(__FILE__) +"/../caramel.rb", args[0])
-
- #File.open('caremelize.rb',"w+") do |f|
- # f << "query_data"
- #end
-
- rescue
- #require 'fileutils'
- #FileUtils.rm_rf(args[0])
- raise
- end
- if commandparser.verbosity == :verbose
- puts "The following files were created in the directory #{args[0]}:"
- #puts paths.sort.join("\n")
- end
+ begin
+
+ # create dummy config file
+ target_file = @config_file.nil? ? "caramel.rb" : @config_file
+
+
+ #puts args[0]
+ require 'fileutils'
+
+ FileUtils.cp(File.dirname(__FILE__) +"/../caramel.rb", target_file)
+
+ rescue
+ #require 'fileutils'
+ #FileUtils.rm_rf(args[0])
+ raise
+ end
+ if commandparser.verbosity == :normal
+ puts "Created new configuration file: #{target_file}"
+ #puts paths.sort.join("\n")
end
end
end
\ No newline at end of file