shell_command 0.1.1 → 0.2.0

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/.travis.yml CHANGED
@@ -3,8 +3,8 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - ruby-head
6
- #- jruby-19mode (Appears to have popen3(…) from 1.8.7)
7
- #- rbx-19mode (Appears to not implement Open3.spawn(…))
6
+ # - jruby-19mode
7
+ - rbx-19mode
8
8
 
9
9
  notifications:
10
10
  irc: "irc.freenode.org#flowof.info"
data/README.md CHANGED
@@ -30,7 +30,7 @@ __1.__
30
30
  if command.success?
31
31
  puts command.stdout
32
32
  else
33
- raise RuntimeError, "The command 'ls' failed."
33
+ puts "Looks like I couldn't execute `ls`, sorry!"
34
34
  end
35
35
  end
36
36
 
@@ -44,10 +44,8 @@ __2.__
44
44
 
45
45
  __SUPPORTED PLATFORMS__
46
46
 
47
- JRuby, and Rubinius do not implement `Open3.popen3(…)` properly yet. :(
48
- As soon as they do they will be supported in 1.9 mode.
49
-
50
- * CRuby 1.9+
47
+ - Rubinius (1.9 mode)
48
+ - CRuby 1.9+
51
49
 
52
50
  __LICENSE__
53
51
 
data/lib/shell_command.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "shell_command/version"
2
- require 'open3'
2
+ require 'open4'
3
3
 
4
4
  module ShellCommand
5
5
 
@@ -16,7 +16,7 @@ module ShellCommand
16
16
  # @attr [String] stdout
17
17
  # The output written by the command to standard output.
18
18
  #
19
- class Command < Struct.new(:status, :stderr, :stdout)
19
+ class Command < Struct.new(:status, :stdout, :stderr)
20
20
 
21
21
  def method_missing method, *args, &block
22
22
  if status.respond_to?(method)
@@ -34,7 +34,7 @@ module ShellCommand
34
34
 
35
35
  #
36
36
  # @param [String] *args
37
- # A command and its arguments to execute (if any).
37
+ # A command and its arguments(if any) to execute.
38
38
  #
39
39
  # @yieldparam [ShellCommand::Command] command
40
40
  # Yields {ShellCommand::Command} if a block is given.
@@ -46,16 +46,15 @@ module ShellCommand
46
46
  if args.empty?
47
47
  raise ArgumentError, 'Wrong number of arguments (0 for 1)'
48
48
  end
49
-
50
- Open3.popen3(*args) do |_, stdout, stderr, thr|
51
- status = thr.value
52
- command = Command.new(status, stderr.read, stdout.read)
53
-
54
- if block_given?
55
- yield(command)
56
- else
57
- command
58
- end
49
+
50
+ pid, stdin, stdout, stderr = Open4.open4(*args)
51
+ _, status = Process.wait2(pid)
52
+ command = Command.new(status, stdout.read, stderr.read)
53
+
54
+ if block_given?
55
+ yield command
56
+ else
57
+ command
59
58
  end
60
59
  end
61
60
  module_function :run
@@ -1,3 +1,3 @@
1
1
  module ShellCommand
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.required_ruby_version = '~> 1.9.1'
25
25
 
26
+ s.add_runtime_dependency "open4"
26
27
  s.add_development_dependency "rake"
27
28
  s.add_development_dependency "minitest"
28
29
 
@@ -1,22 +1,22 @@
1
1
  context ShellCommand do
2
2
 
3
3
  context 'run' do
4
- it 'must successfully execute "echo".' do
4
+ it 'executes a command successfully.' do
5
5
  command = ShellCommand.run "echo -n Hi!"
6
6
  command.success?.must_equal(true)
7
7
  end
8
8
 
9
- it 'must give access to the standard output of "echo"' do
9
+ it 'gives access to the standard output of a command.' do
10
10
  command = ShellCommand.run "echo -n Hi!"
11
11
  command.stdout.must_equal("Hi!")
12
12
  end
13
13
 
14
- it 'must give access to the standard error output of "echo"' do
14
+ it 'gives access to the standard error output of a command.' do
15
15
  command = ShellCommand.run "ls /i_do_not_exist"
16
16
  command.stderr.empty?.must_equal(false)
17
17
  end
18
18
 
19
- it 'must call a block, if given.' do
19
+ it 'calls a block, if given.' do
20
20
  mock = MiniTest::Mock.new
21
21
  mock.expect(:ok, nil)
22
22
 
@@ -27,13 +27,13 @@ context ShellCommand do
27
27
  mock.verify
28
28
  end
29
29
 
30
- it "must yield a parameter, if asked." do
30
+ it "yields a parameter, if given." do
31
31
  ShellCommand.run "ls" do |command|
32
32
  command.must_be_instance_of(ShellCommand::Command)
33
33
  end
34
34
  end
35
35
 
36
- it 'must raise a ArgumentError if given no arguments.' do
36
+ it 'raises an ArgumentError if given no arguments.' do
37
37
  proc {
38
38
  ShellCommand.run
39
39
  }.must_raise(ArgumentError)
@@ -41,13 +41,13 @@ context ShellCommand do
41
41
  end
42
42
 
43
43
  context 'run!' do
44
- it 'must raise a exception when a command fails.' do
44
+ it 'raises ShellCommand::Exception when a command fails.' do
45
45
  proc {
46
46
  ShellCommand.run! "ls /opskddiofjfsiodjf"
47
47
  }.must_raise(ShellCommand::Exception)
48
48
  end
49
49
 
50
- it 'must give a Command when a command is successful.' do
50
+ it 'gives a ShellCommand::Command when a command is successful.' do
51
51
  command = ShellCommand.run! "ls"
52
52
  command.must_be_instance_of(ShellCommand::Command)
53
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shell_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-01 00:00:00.000000000 Z
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: open4
16
+ requirement: &70169586060480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70169586060480
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rake
16
- requirement: &70177434104300 !ruby/object:Gem::Requirement
27
+ requirement: &70169586094980 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70177434104300
35
+ version_requirements: *70169586094980
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: minitest
27
- requirement: &70177434103840 !ruby/object:Gem::Requirement
38
+ requirement: &70169586092480 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70177434103840
46
+ version_requirements: *70169586092480
36
47
  description: shell_command tries to provide a better interface for communicating
37
48
  with commands you spawn on the shell
38
49
  email:
@@ -74,10 +85,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
85
  version: '0'
75
86
  segments:
76
87
  - 0
77
- hash: 1630982936348667376
88
+ hash: 2310391994670122031
78
89
  requirements: []
79
90
  rubyforge_project: shell_command
80
- rubygems_version: 1.8.15
91
+ rubygems_version: 1.8.11
81
92
  signing_key:
82
93
  specification_version: 3
83
94
  summary: shell_command tries to provide a better interface for communicating with