Sha256: 6ef5b76d00936e7069fd80e6b479424bd5534a9db1639df81f95fe5611f73e29
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
# ~*~ encoding: utf-8 ~*~ require 'aladdin' require 'optparse' require 'spirit/constants' module Aladdin module Commands # @example # $> aladdin new path/to/lesson/root module New # Array of skeleton files to be copied over. FILES = ['images', Spirit::MANIFEST, Spirit::INDEX] # Array of dot files to be copied over and renamed. DOT_FILES = %w(gitignore) # Flags for {::FileUtils.cp_r} COPY_FLAGS = {verbose: true} # Copies skeleton files to given destination. # @param [String] dest destination path # @param [Hash] flags options for {::FileUtils.cp_r} # @return [Void] def copy_files(dest, flags={}) flags = COPY_FLAGS.merge flags paths = FILES.map { |file| path_to file } FileUtils.cp_r paths, dest, flags DOT_FILES.each do |file| FileUtils.cp_r path_to(file), File.join(dest, '.' + file), flags end end # Prefixes +file+ with the skeleton directory. # @param [String] file name of file to resolve # @return [String] path def path_to(file) File.expand_path file, Aladdin::PATHS.skeleton end # Parses the command line arguments. # @param [Array] argv command line arguments # @return [Void] def parse!(argv) opt_parser = OptionParser.new do |opts| opts.banner = "Usage: aladdin new [options] [LESSON_PATH]" end opt_parser.parse! argv end extend self Commands.register do def new(argv=ARGV, opts={}) New.parse! argv New.copy_files(argv[0] || Dir.pwd, opts) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aladdin-0.2 | lib/aladdin/commands/new.rb |
aladdin-0.1.0.pre.1 | lib/aladdin/commands/new.rb |
aladdin-0.1.0.pre | lib/aladdin/commands/new.rb |