gofer 0.2.0 → 0.2.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.
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Revision History
2
2
 
3
+ ### v0.2.1 08/05/2011
4
+
5
+ * Add `quiet=` to Host instance to allow setting quiet to be the default.
6
+
3
7
  ### v0.2.0 03/05/2011
4
8
 
5
9
  * Flip ordering of username/hostname on instantiation to match that of Net::SSH
data/README.md CHANGED
@@ -36,7 +36,7 @@
36
36
 
37
37
  ### Respond to command errors
38
38
 
39
- h.run "false" # this will fail
39
+ h.run "false" # this will raise an error
40
40
  response = h.run "false", :capture_exit_status => true # this won't ...
41
41
  puts response.exit_status # and will make the exit status available
42
42
 
@@ -50,8 +50,9 @@
50
50
 
51
51
  ### Suppress output
52
52
 
53
- h.run "echo noisy", :quiet => true # don't output from our command
54
- h.run "echo noisier 1>&2", :quiet_stderr => true # don't even output stderr!
53
+ h.run "echo noisy", :quiet => true # don't print stdout
54
+ h.run "echo noisier 1>&2", :quiet_stderr => true # don't print stderr
55
+ h.quiet = true # never print stdout
55
56
 
56
57
  ## Planned Features
57
58
 
@@ -8,6 +8,7 @@ module Gofer
8
8
  class Host
9
9
 
10
10
  attr_reader :hostname
11
+ attr_accessor :quiet
11
12
 
12
13
  # Create a new Host connection
13
14
  #
@@ -15,6 +16,7 @@ module Gofer
15
16
  # See http://net-ssh.github.com/ssh/v2/api/index.html for valid arguments.
16
17
  def initialize _hostname, username, opts={}
17
18
  @hostname = _hostname
19
+ @quiet = false
18
20
 
19
21
  # support legacy positional argument use
20
22
  if opts.is_a? String
@@ -39,10 +41,11 @@ module Gofer
39
41
  #
40
42
  # Options:
41
43
  #
42
- # +quiet+:: Don't print +stdout+
44
+ # +quiet+:: Don't print +stdout+, can also be set with +quiet=+ on the instance
43
45
  # +quiet_stderr+:: Don't print +stderr+
44
46
  # +capture_exit_status+:: Don't raise an error on a non-zero exit status
45
47
  def run command, opts={}
48
+ opts[:quiet] = quiet unless opts.include?(:quiet)
46
49
  response = @ssh.run command, opts
47
50
  if !opts[:capture_exit_status] && response.exit_status != 0
48
51
  raise HostError.new(self, "Command #{command} failed with exit status #{@ssh.last_exit_status}")
@@ -40,6 +40,7 @@ module Gofer
40
40
  stdout, stderr, output = '', '', ''
41
41
  exit_code = 0
42
42
  ssh.open_channel do |channel|
43
+
43
44
  channel.exec(command) do |ch, success|
44
45
  unless success
45
46
  raise "Couldn't execute command #{command} (ssh channel failure)"
@@ -1,3 +1,3 @@
1
1
  module Gofer # :nodoc:
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -31,6 +31,7 @@ describe Gofer do
31
31
 
32
32
  before :all do
33
33
  @host = Gofer::Host.new(HOSTNAME, USERNAME, :keys => [IDENTITY_FILE])
34
+ @host.quiet = true
34
35
  @tmpdir = raw_ssh("mktemp -d /tmp/gofertest.XXXXX").chomp
35
36
  end
36
37
 
@@ -61,7 +62,7 @@ describe Gofer do
61
62
  describe :run do
62
63
  describe "with stdout and stderr responses" do
63
64
  before :all do
64
- @response = @host.run "echo stdout; echo stderr 1>&2", :quiet => true, :quiet_stderr => true
65
+ @response = @host.run "echo stdout; echo stderr 1>&2", :quiet_stderr => true
65
66
  end
66
67
 
67
68
  it "should capture stdout in @response.stdout" do
@@ -80,7 +81,7 @@ describe Gofer do
80
81
  @response.should == "stdout\n"
81
82
  end
82
83
  end
83
-
84
+
84
85
  it "should error if a command returns a non-zero response" do
85
86
  lambda {@host.run "false"}.should raise_error /failed with exit status/
86
87
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gofer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
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-03 00:00:00 +10:00
13
+ date: 2011-05-08 00:00:00 +10:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency