Class: QuickStart::CLI
- Inherits:
-
Escort::ActionCommand::Base
- Object
- Escort::ActionCommand::Base
- QuickStart::CLI
- Includes:
- Contracts
- 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
30 31 32 33 34 35 36 37 |
# File 'lib/quickstart/cli.rb', line 30 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
49 50 51 52 53 54 55 56 |
# File 'lib/quickstart/cli.rb', line 49 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
11 12 13 14 15 16 |
# File 'lib/quickstart/cli.rb', line 11 def execute arguments.each do |name| fail IOError, "#{name} already exists." if Dir.exist? name generate name end end |
#generate(name) ⇒ Object
24 25 26 27 |
# File 'lib/quickstart/cli.rb', line 24 def generate(name) create_directories name create_files name end |
#substitute(string) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/quickstart/cli.rb', line 40 def substitute(string) string.dup.tap do |copy| .each do |key, value| copy.gsub! "__#{key}__", value.to_s.downcase end end end |
#template ⇒ Object
19 20 21 |
# File 'lib/quickstart/cli.rb', line 19 def template @template ||= QuickStart::Template.new .fetch :template end |