Class: Finder
- Inherits:
-
Object
- Object
- Finder
- Defined in:
- lib/finder.rb
Class Method Summary collapse
Class Method Details
.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 |
.detect_cluster(id) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/finder.rb', line 2 def self.detect_cluster(id) result = [] Civo::Kubernetes.all.items.each do |cluster| result << cluster end if id.blank? if result.count == 1 return result[0] elsif result.count > 1 puts 'Multiple possible Kubernetes clusters found. Please try again and specify the cluster with --cluster=NAME.' exit 1 end end matched = result.detect { |cluster| cluster.name == id || cluster.id == id } return matched if matched result.select! { |cluster| cluster.name.include?(id) || cluster.id.include?(id) } if result.count.zero? puts "No Kubernetes clusters found for '#{id}'. Please check your query." exit 1 elsif result.count > 1 puts "Multiple possible Kubernetes clusters found for '#{id}'. Please try with a more specific query." exit 1 else result[0] end end |