Class: Jarl::CLI
- Inherits:
-
Thor
- Object
- Thor
- Jarl::CLI
- Defined in:
- lib/jarl/cli.rb
Instance Method Summary collapse
- #build(*names) ⇒ Object
- #config ⇒ Object
- #down(*names) ⇒ Object
- #execute(name, command = nil, *args) ⇒ Object
- #inspect(*names) ⇒ Object
- #logs(*names) ⇒ Object
- #pull(*names) ⇒ Object
- #ssh(name, command = nil, *args) ⇒ Object
- #status(*names) ⇒ Object
- #up(*names) ⇒ Object
- #version ⇒ Object
Instance Method Details
#build(*names) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/jarl/cli.rb', line 117 def build(*names) Jarl.load() apps = Jarl.find_applications_by(names) apps.select(&:image_is_a_path?).each do |app| puts esc_yellow "Building image for '#{app}'..." app.build end end |
#config ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jarl/cli.rb', line 15 def config Jarl.load() puts esc_yellow('config:') + " #{Jarl.config.path}" Jarl.config.params.each do |key, value| puts " #{key}: #{value.inspect}" end puts esc_yellow('jarl files:') Jarl.jarl_files.each do |jarl_file| puts " #{jarl_file.path}" jarl_file.applications.each do |app| puts " #{app.name}" end end end |
#down(*names) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/jarl/cli.rb', line 61 def down(*names) Jarl.load() ais = Jarl.find_application_instances_by(names).select(&:running?) puts esc_yellow 'No running applications found' unless ais.size > 0 ais.each do |i| puts esc_yellow "Stopping '#{i.full_name}'..." i.stop! end end |
#execute(name, command = nil, *args) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/jarl/cli.rb', line 72 def execute(name, command = nil, *args) Jarl.load() apps = Jarl.find_applications_by(name) if apps.size > 1 puts esc_yellow 'More than one application matches the pattern, using the first one:' puts esc_yellow " #{apps.map(&:full_name).join(', ')}" end app = apps.first abort "Failed to find application by name: '#{name}'" unless app app.execute(command, args) end |
#inspect(*names) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/jarl/cli.rb', line 103 def inspect(*names) Jarl.load() ais = Jarl.find_application_instances_by(names).select(&:running?) abort 'No running applications found' unless ais.size > 0 ais.each do |ai| if [:ip] puts ai.container.ip else show_jarl_application_instance_inspect(ai) end end end |
#logs(*names) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/jarl/cli.rb', line 137 def logs(*names) Jarl.load() ais = Jarl.find_application_instances_by(names) threads = [] ais.select(&:running?).flatten.each do |instance| threads << Thread.new { instance.tail_log } end begin threads.flatten.each(&:join) rescue Interrupt # end puts end |
#pull(*names) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/jarl/cli.rb', line 127 def pull(*names) Jarl.load() apps = Jarl.find_applications_by(names) apps.select(&:image_is_a_registry_path?).each do |app| puts esc_yellow "Pulling image '#{app}'..." app.pull end end |
#ssh(name, command = nil, *args) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jarl/cli.rb', line 86 def ssh(name, command = nil, *args) Jarl.load() ais = Jarl.find_application_instances_by(name).select(&:running?) abort 'No running applications found' unless ais.size > 0 if ais.size > 1 puts esc_yellow 'More than one running application instance matches the pattern, using the first one:' puts esc_yellow " #{ais.map(&:full_name).join(', ')}" end app = ais.first abort "Failed to find application by name: '#{name}'" unless app abort "Application is not running: '#{app.full_name}'" unless app.running? app.ssh([command] + args) end |
#status(*names) ⇒ Object
32 33 34 35 36 |
# File 'lib/jarl/cli.rb', line 32 def status(*names) Jarl.load() ais = Jarl.find_application_instances_by(names) show_jarl_application_instances_status(ais) end |
#up(*names) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jarl/cli.rb', line 40 def up(*names) Jarl.load() if Jarl.find_application_instances_by(names).any?(&:running?) down(*names) Jarl.reload! end ais = Jarl.find_application_instances_by(names) ais.each do |i| puts esc_green "Starting '#{i.full_name}'..." i.start! end # apps = name ? Jarl.find_applications_by(name) : Jarl.applications # apps.each do |app| # puts esc_green(app.running? ? "Restarting '#{app}'..." : "Starting '#{app}'...") # app.start # end # show_jarl_applications_status(apps) end |
#version ⇒ Object
154 155 156 |
# File 'lib/jarl/cli.rb', line 154 def version puts app_name_version end |