Class: Lando::Generator::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/lando/generator/application.rb

Class Method Summary collapse

Class Method Details

.run!(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lando/generator/application.rb', line 13

def run!(*args)
  opts = Slop.parse do |o|
    
    o.banner = 
%{lando is a landing page generator for Middleman.

Usage: 
  lando create <folder> <template> 
    Generate an empty landing page in the given folder, based on the specified 
    template. 

    NOTE: the folder must not already exist.
  lando ls 
    List all available templates.
  lando preview <template>
    Open a preview (in the default Internet browser) of the specified template.
}

    o.separator "Optional parameters:"

    o.bool "-h", "--help", "print helpful information"
    o.on '-v', '--version', 'print the version' do
      puts "Version: #{Lando::Version::STRING}"
      exit
    end
  end

  args = opts.arguments.dup

  if args.count > 0 && opts[:help] == false
    cmd = args.shift
    klass_name = "Lando::Generator::Command::#{cmd.capitalize}"
    begin
      cmd_handler_klass = Object.const_get(klass_name)
      cmd_handler_klass.send('execute', *args)
      exit
    rescue NameError => e
      STDERR.puts "Invalid command: #{cmd}: #{e.to_s}".red
    rescue ArgumentError => e
      STDERR.puts "Error: #{e.to_s}".red
    end
  end

  puts opts.to_s(prefix: ' ')
end