command-runner 0.4.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -104,6 +104,8 @@ module Command
104
104
  raise NoCommandError, @command
105
105
  end
106
106
 
107
+ alias_method :run!, :pass!
108
+
107
109
  # Runs the command and arguments with the given interpolations;
108
110
  # defaults to no interpolations. Calls {#pass!}, but does not
109
111
  # raise an error.
@@ -124,6 +126,8 @@ module Command
124
126
  end
125
127
  end
126
128
 
129
+ alias_method :run, :pass
130
+
127
131
  # The command line being run by the runner. Interpolates the
128
132
  # arguments with the given interpolations.
129
133
  #
@@ -6,6 +6,7 @@ module Command
6
6
  # different method of executing the process.
7
7
  module Backends
8
8
 
9
+ autoload :SSH, "command/runner/backends/ssh"
9
10
  autoload :Fake, "command/runner/backends/fake"
10
11
  autoload :Spawn, "command/runner/backends/spawn"
11
12
  autoload :Backticks, "command/runner/backends/backticks"
@@ -19,6 +19,7 @@ module Command
19
19
  # Run the given command and arguments, in the given environment.
20
20
  #
21
21
  # @raise [Errno::ENOENT] if the command doesn't exist.
22
+ # @yield [Message] when the command finishes.
22
23
  # @param command [String] the command to run.
23
24
  # @param arguments [String] the arguments to pass to the
24
25
  # command.
@@ -28,7 +28,7 @@ module Command
28
28
  # @abstract
29
29
  # @note Does nothing.
30
30
  # @raise [Errno::ENOENT] if the command doesn't exist.
31
- # @yield [message] when the command finishes.
31
+ # @yield [Message] when the command finishes.
32
32
  # @param command [String] the command to run.
33
33
  # @param arguments [String] the arguments to pass to the
34
34
  # command.
@@ -0,0 +1,87 @@
1
+ module Command
2
+ class Runner
3
+ module Backends
4
+
5
+ # SSHs into a remote and runs commands there.
6
+ #
7
+ # @note The message that is returned by this may not be entirely
8
+ # filled with data, since some of it may not be able to be
9
+ # accessible.
10
+ class SSH < Fake
11
+
12
+ # (see Fake.available?)
13
+ def self.available?
14
+ begin
15
+ require 'net/ssh'
16
+ true
17
+ rescue LoadError
18
+ false
19
+ end
20
+ end
21
+
22
+ # Initializes the backend.
23
+ #
24
+ # @param host [String] the host to connect to.
25
+ # @param user [String] the user to log in as.
26
+ # @param options [Hash] the options to pass to Net::SSH.
27
+ def initialize(host, user, options = {})
28
+ super()
29
+ @net_ssh = Net::SSH.start(host, user, options)
30
+ end
31
+
32
+ # (see Spawn#call)
33
+ def call(command, arguments, env = {}, options = {}, &block)
34
+ super
35
+ mdata = { :stdout => "", :stderr => "", :env => env, :options => {} }
36
+ channel = @net_ssh.open_channel do |ch|
37
+
38
+
39
+ ch.exec "#{command} #{arguments}" do |sch, success|
40
+ raise Errno::ENOENT unless success
41
+
42
+ env.each do |k, v|
43
+ sch.env k.to_s, v
44
+ end
45
+
46
+ sch.on_data do |_, data|
47
+ mdata[:stdout] << data
48
+ end
49
+
50
+ sch.on_extended_data do |_, type, data|
51
+ mdata[:stderr] << data if type == 1
52
+ end
53
+
54
+ sch.on_request "exit-status" do |_, data|
55
+ mdata[:exit_code] = data.read_long
56
+ end
57
+
58
+ sch.on_close do
59
+ mdata[:executed] = true
60
+ mdata[:finished] = true
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ future do
67
+ start_time = Time.now
68
+ channel.wait
69
+ end_time = Time.now
70
+ channel.close
71
+
72
+ mdata[:time] = (end_time - start_time).abs
73
+
74
+ message = Message.new mdata
75
+
76
+ if block_given?
77
+ block.call(message)
78
+ else
79
+ message
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
@@ -3,7 +3,7 @@ module Command
3
3
  class Runner
4
4
 
5
5
  # The current version of Runner.
6
- VERSION = "0.4.1".freeze
6
+ VERSION = "0.6.1".freeze
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-23 00:00:00.000000000 Z
12
+ date: 2013-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: promise
@@ -73,6 +73,7 @@ files:
73
73
  - lib/command/runner/message.rb
74
74
  - lib/command/runner/backends/fake.rb
75
75
  - lib/command/runner/backends/backticks.rb
76
+ - lib/command/runner/backends/ssh.rb
76
77
  - lib/command/runner/backends/posix_spawn.rb
77
78
  - lib/command/runner/backends/spawn.rb
78
79
  - lib/command/runner.rb