Class: Geoffrey::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/geoffrey/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#packageObject

Returns the value of attribute package.



6
7
8
# File 'lib/geoffrey/cli.rb', line 6

def package
  @package
end

Instance Method Details

#install(*names) ⇒ Object



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
# File 'lib/geoffrey/cli.rb', line 20

def install(*names)

  templates_to_install = []

  # if a remote flag is on, then we'll take the parameter as an url, and will
  # then fetch it directly instead of looking for it in the filesystem
  # templates.
  if options[:remote]
    templates_to_install << names.join
  else
    names.each do |name|
      if file = file_for_template(name)
        templates_to_install << file
      end
    end
  end

  if templates_to_install.empty?
    puts "Template not found"
    exit 1
  else
    templates_to_install.each do |template|
      package = Geoffrey::Template.new(template).package
      package.verbose(true) if options[:verbose]
      package.process
    end
  end
end

#list(filter = '') ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/geoffrey/cli.rb', line 9

def list(filter = '')
  names = if filter && filter != ''
    list_of_template_names.select{ |name| name.downcase.include?(filter.downcase) }
  else
    list_of_template_names
  end
  puts names.join(' ')
end

#search(pattern) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/geoffrey/cli.rb', line 50

def search(pattern)
  fitting_packages = packages.select{ |pack| pack.fits?(pattern) }
  if fitting_packages && !fitting_packages.empty?
    fitting_packages.each do |pack|
      line = pack.name
      line << ": #{pack.description}" if pack.description && pack.description != ""
      puts line
    end
  else
    puts "No templates available fit that description"
  end
end