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 +2 -2
- data/README.md +3 -5
- data/lib/shell_command.rb +12 -13
- data/lib/shell_command/version.rb +1 -1
- data/shell_command.gemspec +1 -0
- data/test/test_shell_command.rb +8 -8
- metadata +19 -8
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -30,7 +30,7 @@ __1.__
|
|
30
30
|
if command.success?
|
31
31
|
puts command.stdout
|
32
32
|
else
|
33
|
-
|
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
|
-
|
48
|
-
|
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 '
|
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, :
|
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
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
data/shell_command.gemspec
CHANGED
data/test/test_shell_command.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
context ShellCommand do
|
2
2
|
|
3
3
|
context 'run' do
|
4
|
-
it '
|
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 '
|
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 '
|
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 '
|
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 "
|
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 '
|
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 '
|
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 '
|
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.
|
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-
|
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: &
|
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: *
|
35
|
+
version_requirements: *70169586094980
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: minitest
|
27
|
-
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: *
|
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:
|
88
|
+
hash: 2310391994670122031
|
78
89
|
requirements: []
|
79
90
|
rubyforge_project: shell_command
|
80
|
-
rubygems_version: 1.8.
|
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
|