Module: Kleiber::Commands
- Included in:
- Project
- Defined in:
- lib/kleiber/commands.rb
Instance Method Summary collapse
-
#apply_env_line(env_to_app) ⇒ String
Returns string of environment variable definitions.
-
#handle_halt(_params) ⇒ String
Returns command line for ‘vagrant halt` command.
-
#handle_reload(params) ⇒ String
Returns command line for ‘vagrant reload` command.
-
#handle_ssh(params) ⇒ String
Returns command line for ‘vagrant ssh` command.
-
#handle_up(params) ⇒ String
Returns command line for ‘vagrant up` command.
-
#in_machine(params) ⇒ String
Returns commandline need to execute in vagrant machine.
-
#scriptify(command) ⇒ String
Returns text of bashscript file with command.
-
#ssh_exec_line(params) ⇒ String
Returns option which executes tasks in vagrant.
-
#tasks_line(tasks_to_run) ⇒ String
Returns tasks chain command line.
-
#terminal_execute(command) ⇒ Object
Executes command in new tab.
- #vagrant ⇒ Object
-
#vagrant_(command) ⇒ String
Returns vagrant command.
-
#vagrant_destroy ⇒ Cocaine::CommandLine
Returns vagrant destroy command line.
-
#vagrant_halt ⇒ Cocaine::CommandLine
Returns vagrant halt command line.
-
#vagrant_provision ⇒ Cocaine::CommandLine
Returns vagrant provision command line.
-
#vagrant_reload ⇒ Cocaine::CommandLine
Returns vagrant reload command line.
-
#vagrant_ssh ⇒ Cocaine::CommandLine
Returns vagrant ssh command line.
-
#vagrant_up ⇒ Cocaine::CommandLine
Returns vagrant up command line.
-
#with_tmpfile_script(command) {|file| ... } ⇒ Object
Provides command to execute within temporary bashscript file.
Instance Method Details
#apply_env_line(env_to_app) ⇒ String
Returns string of environment variable definitions
148 149 150 |
# File 'lib/kleiber/commands.rb', line 148 def apply_env_line(env_to_app) env_to_app.map { |e| e.join('=') }.join(' ') end |
#handle_halt(_params) ⇒ String
Returns command line for ‘vagrant halt` command.
107 108 109 |
# File 'lib/kleiber/commands.rb', line 107 def handle_halt(_params) vagrant_(:halt) end |
#handle_reload(params) ⇒ String
Returns command line for ‘vagrant reload` command. Evaluates tasks executions line by taken parameters
98 99 100 101 102 |
# File 'lib/kleiber/commands.rb', line 98 def handle_reload(params) line = [vagrant_(:reload)] line << handle_ssh(params) unless params[:tasks].empty? line.join(' && ') end |
#handle_ssh(params) ⇒ String
Returns command line for ‘vagrant ssh` command. Evaluates tasks executions line by taken parameters
88 89 90 91 92 |
# File 'lib/kleiber/commands.rb', line 88 def handle_ssh(params) line = [vagrant_(:ssh)] line << ssh_exec_line(params) unless params[:tasks].empty? line.join(' ') end |
#handle_up(params) ⇒ String
Returns command line for ‘vagrant up` command. Evaluates tasks executions line by taken parameters
78 79 80 81 82 |
# File 'lib/kleiber/commands.rb', line 78 def handle_up(params) line = [vagrant_(:up)] line << handle_ssh(params) unless params[:tasks].empty? line.join(' && ') end |
#in_machine(params) ⇒ String
Returns commandline need to execute in vagrant machine. Actually, it’s an environment settings and chain of tasks
126 127 128 |
# File 'lib/kleiber/commands.rb', line 126 def in_machine(params) [apply_env_line(params[:env]), tasks_line(params[:tasks])].join(' ') end |
#scriptify(command) ⇒ String
Returns text of bashscript file with command
70 71 72 |
# File 'lib/kleiber/commands.rb', line 70 def scriptify(command) ['#!/bin/bash', 'unset RUBYLIB', command].join("\n") end |
#ssh_exec_line(params) ⇒ String
Returns option which executes tasks in vagrant
116 117 118 |
# File 'lib/kleiber/commands.rb', line 116 def ssh_exec_line(params) Cocaine::CommandLine.new('', '-c :in_machine').command(in_machine: in_machine(params)) end |
#tasks_line(tasks_to_run) ⇒ String
Returns tasks chain command line
135 136 137 138 139 140 141 |
# File 'lib/kleiber/commands.rb', line 135 def tasks_line(tasks_to_run) line = ['cd /vagrant'] line += tasks_to_run.reduce({}) do |result, (key, value)| result.merge(key => tasks[key] || value) end.values line.join(' && ') end |
#terminal_execute(command) ⇒ Object
Executes command in new tab
49 50 51 52 53 |
# File 'lib/kleiber/commands.rb', line 49 def terminal_execute(command) with_tmpfile_script(command) do |file| Kleiber.terminal.execute(file) end end |
#vagrant ⇒ Object
7 8 9 |
# File 'lib/kleiber/commands.rb', line 7 def vagrant Cocaine::CommandLine.new('/usr/bin/vagrant') end |
#vagrant_(command) ⇒ String
Returns vagrant command
155 156 157 |
# File 'lib/kleiber/commands.rb', line 155 def vagrant_(command) send("vagrant_#{command}".to_sym).command end |
#vagrant_destroy ⇒ Cocaine::CommandLine
Returns vagrant destroy command line
37 38 39 |
# File 'lib/kleiber/commands.rb', line 37 def vagrant_destroy Cocaine::CommandLine.new(vagrant.command, 'destroy') end |
#vagrant_halt ⇒ Cocaine::CommandLine
Returns vagrant halt command line
31 32 33 |
# File 'lib/kleiber/commands.rb', line 31 def vagrant_halt Cocaine::CommandLine.new(vagrant.command, 'halt') end |
#vagrant_provision ⇒ Cocaine::CommandLine
Returns vagrant provision command line
43 44 45 |
# File 'lib/kleiber/commands.rb', line 43 def vagrant_provision Cocaine::CommandLine.new(vagrant.command, 'provision') end |
#vagrant_reload ⇒ Cocaine::CommandLine
Returns vagrant reload command line
25 26 27 |
# File 'lib/kleiber/commands.rb', line 25 def vagrant_reload Cocaine::CommandLine.new(vagrant.command, 'reload') end |
#vagrant_ssh ⇒ Cocaine::CommandLine
Returns vagrant ssh command line
19 20 21 |
# File 'lib/kleiber/commands.rb', line 19 def vagrant_ssh Cocaine::CommandLine.new(vagrant.command, 'ssh') end |
#vagrant_up ⇒ Cocaine::CommandLine
Returns vagrant up command line
13 14 15 |
# File 'lib/kleiber/commands.rb', line 13 def vagrant_up Cocaine::CommandLine.new(vagrant.command, 'up') end |
#with_tmpfile_script(command) {|file| ... } ⇒ Object
Provides command to execute within temporary bashscript file
58 59 60 61 62 63 64 65 |
# File 'lib/kleiber/commands.rb', line 58 def with_tmpfile_script(command) Tempfile.create([name, '.sh'], '/tmp') do |file| file.chmod(0_755) file.write(scriptify(command)) file.close yield file end end |