Class: QuickStart::CLI

Inherits:
Escort::ActionCommand::Base
  • Object
show all
Includes:
Contracts::Builtin, Contracts::Core
Defined in:
lib/quickstart/cli.rb

Overview

CommandLine Interface for QuickStart

Instance Method Summary collapse

Instance Method Details

#create_directories(name) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/quickstart/cli.rb', line 31

def create_directories(name)
  Dir.mkdir name
  template.directories.each do |template_dir|
    dir = "#{name}/#{substitute template_dir}"
    puts "Creating #{dir}"
    Dir.mkdir dir unless Dir.exist? dir
  end
end

#create_files(name) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/quickstart/cli.rb', line 50

def create_files(name)
  template.files.each do |template_file|
    file = "#{name}/#{substitute template_file}"
    next if File.directory? file
    puts "Rendering #{file}"
    File.write file, template.render(template_file, command_options)
  end
end

#executeObject



12
13
14
15
16
17
# File 'lib/quickstart/cli.rb', line 12

def execute
  arguments.each do |name|
    fail IOError, "#{name} already exists." if Dir.exist? name
    generate name
  end
end

#generate(name) ⇒ Object



25
26
27
28
# File 'lib/quickstart/cli.rb', line 25

def generate(name)
  create_directories name
  create_files name
end

#substitute(string) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/quickstart/cli.rb', line 41

def substitute(string)
  string.dup.tap do |copy|
    command_options.each do |key, value|
      copy.gsub! "__#{key}__", value.to_s.downcase
    end
  end
end

#templateObject



20
21
22
# File 'lib/quickstart/cli.rb', line 20

def template
  @template ||= QuickStart::Template.new command_options.fetch :template
end