Method: Finder.detect_app

Defined in:
lib/finder.rb

.detect_app(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/finder.rb', line 33

def self.detect_app(name)
  result = []
  apps = Civo::Kubernetes.applications.items
  apps.each do |app|
    result << app if app.name.downcase.include?(name.downcase)
  end

  matched = apps.detect { |app| app.name.downcase == name.downcase }
  return matched if matched

  if result.count.zero?
    puts "No Kubernetes marketplace applications found for '#{name}'. Please check your query."
    exit 1
  elsif result.count > 1
    puts "Multiple possible Kubernetes marketplace applications found for '#{name}'. Please try with a more specific query."
    exit 1
  else
    result[0]
  end
end