Class: QuickStart::CLI
- Inherits:
-
Escort::ActionCommand::Base
- Object
- Escort::ActionCommand::Base
- QuickStart::CLI
- Includes:
- Contracts::Builtin, Contracts::Core
- Defined in:
- lib/quickstart/cli.rb
Overview
CommandLine Interface for QuickStart
Instance Method Summary collapse
- #create_directories(name) ⇒ Object
- #create_files(name) ⇒ Object
- #execute ⇒ Object
- #generate(name) ⇒ Object
- #substitute(string) ⇒ Object
- #template ⇒ Object
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, ) end end |
#execute ⇒ Object
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| .each do |key, value| copy.gsub! "__#{key}__", value.to_s.downcase end end end |
#template ⇒ Object
20 21 22 |
# File 'lib/quickstart/cli.rb', line 20 def template @template ||= QuickStart::Template.new .fetch :template end |