Sha256: ed0bb9152c8c34967d65e065706ede0e47314e8b5ecf1a766b9db845ee74554e

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

#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 = "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.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]"
    end

    # Create a caramelize config file.
    def execute(args)
      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
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
caramelize-0.2.0 lib/caramelize/cli/create_command.rb
caramelize-0.1.2 lib/caramelize/cli/create_command.rb
caramelize-0.1.1 lib/caramelize/cli/create_command.rb
caramelize-0.1.0 lib/caramelize/cli/create_command.rb