trebor 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77026d34d3fdfd41538cdb4b4c3c9234b57a8764
4
- data.tar.gz: a32e91b55ccd3c877d2a840e28bf642079567fc9
3
+ metadata.gz: 079da4c6439097f18efebb8cf2e816a5b0f1812d
4
+ data.tar.gz: 5393b7e32b66a40aa06bf97b999276aa7f2e7b97
5
5
  SHA512:
6
- metadata.gz: 3a9446e16f9d319d7012664c6a48269d7ccb2d45170ba8c2077c35c5995cd427dd4f25d5524551f1809079997fc54aed850ea761ba23b807bab93781977eb424
7
- data.tar.gz: 5fc93aaa5fe0054b7964d8385653ce31ba992ccaadf4d61c00feb976c5afecdeb7587e93b3a66aff44f2873005a941fc70d51db711de71de5473def3d78108f5
6
+ metadata.gz: ff3a86822b910c3de159621a2e604067ed922d171135317488f6cac679dbb19ae827357b3a0e5cbcb27620993eb090c416c0983fe914d758adcded33c7610b92
7
+ data.tar.gz: cfa3b7e2eca42e356758d11fe4a1a94a65bbbfc75eee00d831eee1d729c1aa554e273b4c250286176a107fc78b5743285f42aea40db87734377401d3bc613f95
data/bin/trebor CHANGED
@@ -2,5 +2,7 @@
2
2
 
3
3
  require "rubygems"
4
4
  require "trebor"
5
+ require "net/ssh"
6
+ require "net/scp"
5
7
 
6
8
  Trebor.run *ARGV
@@ -21,5 +21,6 @@ require_relative "trebor/domain"
21
21
  require_relative "trebor/command"
22
22
  require_relative "trebor/context"
23
23
  require_relative "trebor/task"
24
+ require_relative "trebor/on"
24
25
  require_relative "trebor/within"
25
26
  require_relative "trebor/with"
@@ -2,6 +2,10 @@ require "open3"
2
2
 
3
3
  module Trebor
4
4
  module Command
5
+ def on(host, user, options, &block)
6
+ On.new(self, host, user, options).action block
7
+ end
8
+
5
9
  def within(directory, &block)
6
10
  joined_directory = File.join(*[current_directory, directory].compact)
7
11
  message = "Directory does not exist '#{joined_directory}'"
@@ -33,7 +37,7 @@ module Trebor
33
37
  end
34
38
 
35
39
  def test?(name, option)
36
- command = %([ #{option} #{File.join *[current_directory, name].compact} ])
40
+ command = %([ #{option} #{name} ])
37
41
 
38
42
  run(command) == 0
39
43
  end
@@ -42,4 +46,31 @@ module Trebor
42
46
  toplevel.call(*names)
43
47
  end
44
48
  end
49
+
50
+ module RemoteCommand
51
+ include Command
52
+
53
+ def run(command)
54
+ status = nil
55
+
56
+ ssh.open_channel do |channel|
57
+ channel.exec fetch(command) do |ch, success|
58
+ channel.on_data do |ch, data|
59
+ Trebor.logger.info data.chomp
60
+ end
61
+
62
+ channel.on_extended_data do |ch, type, data|
63
+ Trebor.logger.error data.chomp + " [#{type}]"
64
+ end
65
+
66
+ channel.on_request('exit-status') do |ch, data|
67
+ status = data.read_long
68
+ end
69
+ end
70
+ end
71
+
72
+ ssh.loop
73
+ status
74
+ end
75
+ end
45
76
  end
@@ -24,6 +24,10 @@ module Trebor
24
24
  parent && parent.command
25
25
  end
26
26
 
27
+ def ssh
28
+ parent && parent.ssh
29
+ end
30
+
27
31
  def action(block)
28
32
  instance_eval &block
29
33
  end
@@ -0,0 +1,28 @@
1
+ module Trebor
2
+ class On
3
+ include InnerDomain
4
+
5
+ attr_reader :ssh
6
+
7
+ def initialize(parent, host, user, options)
8
+ @ssh = Net::SSH.start(host, user, options)
9
+ @parent = parent
10
+
11
+ self.extend RemoteCommand
12
+ end
13
+
14
+ def command
15
+ RemoteCommand
16
+ end
17
+
18
+ def action(block)
19
+ begin
20
+ instance_eval &block
21
+ rescue => e
22
+ raise e
23
+ ensure
24
+ @ssh.close unless @ssh.closed?
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Trebor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -12,7 +12,7 @@ module Trebor
12
12
  end
13
13
 
14
14
  def fetch(command)
15
- parent.fetch("cd %s; %s" % [directory, command])
15
+ parent.fetch("cd %s; %s" % [current_directory, command])
16
16
  end
17
17
 
18
18
  def current_directory
@@ -12,6 +12,9 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = %q{Trebor is a small DSL}
13
13
  gem.homepage = "https://github.com/daisuko/trebor"
14
14
 
15
+ gem.add_dependency 'net-ssh'
16
+ gem.add_dependency 'net-scp'
17
+
15
18
  gem.add_development_dependency 'rake'
16
19
  gem.add_development_dependency 'minitest'
17
20
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trebor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - daisuko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-30 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-scp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rake
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,6 +84,7 @@ files:
56
84
  - lib/trebor/command.rb
57
85
  - lib/trebor/context.rb
58
86
  - lib/trebor/domain.rb
87
+ - lib/trebor/on.rb
59
88
  - lib/trebor/task.rb
60
89
  - lib/trebor/version.rb
61
90
  - lib/trebor/with.rb