gofer 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # Revision History
2
2
 
3
+ ### v0.2.2 10/05/20011
4
+
5
+ * Add `run_multiple` method to `Gofer::Host`
6
+
3
7
  ### v0.2.1 08/05/2011
4
8
 
5
9
  * Add `quiet=` to Host instance to allow setting quiet to be the default.
6
10
 
7
11
  ### v0.2.0 03/05/2011
8
12
 
9
- * Flip ordering of username/hostname on instantiation to match that of Net::SSH
13
+ * Flip ordering of username/hostname on instantiation to match that of `Net::SSH`
10
14
 
11
15
  ### v0.1.2 03/05/2011
12
16
 
13
- * Pass through Gofer::Host instantiation options straight through to Net::SSH.
17
+ * Pass through `Gofer::Host` instantiation options straight through to `Net::SSH`.
14
18
 
15
19
  ### v0.1.1 23/04/2011
16
20
 
data/README.md CHANGED
@@ -54,6 +54,11 @@
54
54
  h.run "echo noisier 1>&2", :quiet_stderr => true # don't print stderr
55
55
  h.quiet = true # never print stdout
56
56
 
57
+ ### Run multiple commands
58
+
59
+ response = h.run_multiple(['echo hello', 'echo goodbye'], :quiet => true)
60
+ puts response.stdout # will print "hello\ngoodbye\n"
61
+
57
62
  ## Planned Features
58
63
 
59
64
  h.write("a string buffer", 'a_remote_file')
data/lib/gofer/host.rb CHANGED
@@ -52,6 +52,33 @@ module Gofer
52
52
  end
53
53
  response
54
54
  end
55
+
56
+ # Run +commands+ one by one in order.
57
+ #
58
+ # Raise an error if a command in +commands+ exits with a non-zero status.
59
+ #
60
+ # Print +stdout+ and +stderr+ as they're received.
61
+ #
62
+ # Return a Gofer::Response object.
63
+ #
64
+ # Options:
65
+ #
66
+ # +quiet+:: Don't print +stdout+, can also be set with +quiet=+ on the instance
67
+ # +quiet_stderr+:: Don't print +stderr+
68
+ #
69
+ # The behaviour of passing +capture_exit_status+ here is undefined.
70
+ def run_multiple commands, opts={}
71
+ return if commands.empty?
72
+
73
+ responses = commands.map do |command|
74
+ run command, opts
75
+ end
76
+
77
+ first_response = responses.shift
78
+ responses.reduce(first_response) do |cursor, response|
79
+ Response.new(cursor.stdout + response.stdout, cursor.stderr + response.stderr, cursor.output + response.output, 0)
80
+ end
81
+ end
55
82
 
56
83
  # Return +true+ if +path+ exits.
57
84
  def exists? path
data/lib/gofer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gofer # :nodoc:
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -59,29 +59,34 @@ describe Gofer do
59
59
  end
60
60
  end
61
61
 
62
+ shared_examples_for "an output capturer" do
63
+ it "and capture stdout in @response.stdout" do
64
+ @response.stdout.should == "stdout\n"
65
+ end
66
+
67
+ it "and capture stderr in @response.stderr" do
68
+ @response.stderr.should == "stderr\n"
69
+ end
70
+
71
+ it "and combine captured stdout / stderr in @response.output" do
72
+ @response.output.should == "stdout\nstderr\n"
73
+ end
74
+
75
+ it "and @response by itself should be the captured stdout" do
76
+ @response.should == "stdout\n"
77
+ end
78
+ end
79
+
62
80
  describe :run do
63
- describe "with stdout and stderr responses" do
81
+
82
+ describe "with a stdout and stderr responses" do
64
83
  before :all do
65
84
  @response = @host.run "echo stdout; echo stderr 1>&2", :quiet_stderr => true
66
85
  end
67
-
68
- it "should capture stdout in @response.stdout" do
69
- @response.stdout.should == "stdout\n"
70
- end
71
-
72
- it "should capture stderr in @response.stderr" do
73
- @response.stderr.should == "stderr\n"
74
- end
75
-
76
- it "should combine captured stdout / stderr in @response.output" do
77
- @response.output.should == "stdout\nstderr\n"
78
- end
79
-
80
- it "@response by itself should be the captured stdout" do
81
- @response.should == "stdout\n"
82
- end
83
- end
84
86
 
87
+ it_should_behave_like "an output capturer"
88
+ end
89
+
85
90
  it "should error if a command returns a non-zero response" do
86
91
  lambda {@host.run "false"}.should raise_error /failed with exit status/
87
92
  end
@@ -91,7 +96,20 @@ describe Gofer do
91
96
  response.exit_status.should == 1
92
97
  end
93
98
  end
94
-
99
+
100
+ describe :run_multiple do
101
+ describe "with stdout and stderr responses" do
102
+ before :all do
103
+ @response = @host.run_multiple ["echo stdout", "echo stderr 1>&2"], :quiet_stderr => true
104
+ end
105
+ it_should_behave_like "an output capturer"
106
+ end
107
+
108
+ it "should error if a command returns a non-zero response" do
109
+ lambda {@host.run_multiple ["echo", "false"]}.should raise_error /failed with exit status/
110
+ end
111
+ end
112
+
95
113
  describe :exists? do
96
114
  it "should return true if a path or file exists" do
97
115
  raw_ssh "touch #{in_tmpdir 'exists'}"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gofer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Pearson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-08 00:00:00 +10:00
13
+ date: 2011-05-10 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency