Class: Kamaze::Project::Tools::Vagrant::Remote
- Defined in:
- lib/kamaze/project/tools/vagrant/remote.rb,
lib/kamaze/project/tools/vagrant/remote.rb
Overview
Provide remote command execution (ssh)
Commands can use aliases through configuration: box_id.ssh.aliases
;
where box_id
is the box identifier.
Instance Attribute Summary collapse
- #boxes ⇒ Hash readonly
Instance Method Summary collapse
-
#apply_alias(box_id, command) ⇒ String|nil
protected
Apply alias on command for given
box_id
. -
#execute(*params, &block) ⇒ Object
Run a command remotely on box identified by
box_id
. -
#initialize(boxes, options = {}) ⇒ Remote
constructor
Initialize remote shell with given boxes and options.
- #to_a ⇒ Array
Constructor Details
#initialize(boxes, options = {}) ⇒ Remote
Initialize remote shell with given boxes and options
29 30 31 32 33 |
# File 'lib/kamaze/project/tools/vagrant/remote.rb', line 29 def initialize(boxes, = {}) @boxes = boxes super() end |
Instance Attribute Details
#boxes ⇒ Hash (readonly)
23 24 25 |
# File 'lib/kamaze/project/tools/vagrant/remote.rb', line 23 def boxes @boxes end |
Instance Method Details
#apply_alias(box_id, command) ⇒ String|nil (protected)
Apply alias on command for given box_id
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kamaze/project/tools/vagrant/remote.rb', line 65 def apply_alias(box_id, command) return unless command conf = boxes.fetch(box_id.to_s) # fetch related config args = Shellwords.split(command) # command split into words exeb = conf['ssh']['aliases'][args[0]] # executable if exeb command = Shellwords.split(exeb) .concat(args.drop(1)) .yield_self { |c| Shellwords.shelljoin(c) } end command end |
#execute(*params, &block) ⇒ Object
Run a command remotely on box identified by box_id
Sample of use:
remote.execute(:freebsd)
remote.execute(:freebsd, 'rake clobber')
At least, one argument is required.
50 51 52 53 54 55 56 |
# File 'lib/kamaze/project/tools/vagrant/remote.rb', line 50 def execute(*params, &block) box_id = params.fetch(0) command = apply_alias(box_id, params[1]) # remote command params = command ? [box_id, '-c', command] : [box_id] super(*params, &block) end |
#to_a ⇒ Array
36 37 38 |
# File 'lib/kamaze/project/tools/vagrant/remote.rb', line 36 def to_a super.push('ssh') end |