Class: Templater::CLI::Manifold

Inherits:
Object
  • Object
show all
Defined in:
lib/templater/cli/manifold.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination_root, manifold, name, version) ⇒ Manifold

Returns a new instance of Manifold.



7
8
9
# File 'lib/templater/cli/manifold.rb', line 7

def initialize(destination_root, manifold, name, version)
  @destination_root, @manifold, @name, @version = destination_root, manifold, name, version
end

Class Method Details

.run(destination_root, manifold, name, version, arguments) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/templater/cli/manifold.rb', line 16

def self.run(destination_root, manifold, name, version, arguments)
  if arguments.blank? || (arguments.first && ["help", "-h", "--help"].include?(arguments.first))
    Manifold.new(destination_root, manifold, name, version).run(arguments)
    return
  end

  generator_name = arguments.shift
  if generator_class = manifold.generator(generator_name)
    Generator.new(generator_name, generator_class, destination_root, name, version).run(arguments)
  else
    Manifold.new(destination_root, manifold, name, version).run(arguments)
  end
end

Instance Method Details

#helpObject

outputs a helpful message and quits



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/templater/cli/manifold.rb', line 36

def help
  puts "Usage: #{@name} generator_name [options] [args]"
  puts ''
  puts @manifold.desc
  puts ''
  puts 'Available generators'
  @manifold.public_generators.sort do |one, other|
    one[0].to_s <=> other[0].to_s
  end.each do |name, generator|
    print "    "
    print name.to_s.ljust(33)
    print generator.desc.to_lines.first.chomp if generator.desc
    print "\n"
  end
  puts @options[:opts]
  puts ''
  exit
end

#run(arguments) ⇒ Object



30
31
32
33
# File 'lib/templater/cli/manifold.rb', line 30

def run(arguments)
  @options = Templater::CLI::Parser.parse(arguments)
  self.help
end

#versionObject



11
12
13
14
# File 'lib/templater/cli/manifold.rb', line 11

def version
  puts @version
  exit
end