sfl 2.1 → 2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/lib/sfl.rb +12 -5
- data/spec/mocker.rb +5 -0
- data/spec/mocker_output.txt +50 -0
- data/spec/sfl_spec.rb +28 -0
- metadata +19 -7
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 2.2
|
2
|
+
|
3
|
+
* support command lines including shell special characters
|
4
|
+
* bugfix: sfl won't re-define Kernel.spawn on Ruby 1.9
|
5
|
+
|
6
|
+
# 2.1
|
7
|
+
|
8
|
+
* Livence: the 2-clause BSDL or the Ruby licence.
|
9
|
+
|
1
10
|
# 2.0
|
2
11
|
|
3
12
|
Version 2.0 is done completely by Bernard Lambeau. Thanks!
|
data/lib/sfl.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class SFL
|
2
|
-
VERSION = "2.
|
2
|
+
VERSION = "2.2".freeze
|
3
|
+
|
4
|
+
SHELL_SPECIALS = %r([\*\?\{\}\[\]<>\(\)~&\|\\\$;'`"\n])m.freeze
|
3
5
|
|
4
6
|
attr_reader :command, :environment, :argument, :option
|
5
7
|
|
@@ -29,9 +31,14 @@ class SFL
|
|
29
31
|
if cmdandarg.size == 1
|
30
32
|
cmdandarg = cmdandarg.first
|
31
33
|
if String === cmdandarg
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
if SHELL_SPECIALS === cmdandarg
|
35
|
+
@command = cmdandarg
|
36
|
+
@argument = []
|
37
|
+
else
|
38
|
+
cmd, *arg = self.class.parse_command_with_arg(cmdandarg)
|
39
|
+
@command = [cmd, cmd]
|
40
|
+
@argument = arg
|
41
|
+
end
|
35
42
|
else
|
36
43
|
@command = cmdandarg
|
37
44
|
@argument = []
|
@@ -174,7 +181,7 @@ class SFL
|
|
174
181
|
end
|
175
182
|
end
|
176
183
|
|
177
|
-
if RUBY_VERSION
|
184
|
+
if RUBY_VERSION < "1.9"
|
178
185
|
def Kernel.spawn(*x)
|
179
186
|
SFL.new(*x).run
|
180
187
|
end
|
data/spec/mocker.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Spawn for Legacy
|
2
|
+
|
3
|
+
![demo](http://gyazo.com/e22144b2aadbbecfc43761f95c27bf3e.png)
|
4
|
+
|
5
|
+
Kernel.spawn in ruby 1.9 solves all issues on asynchronous executions[[1]](http://ujihisa.blogspot.com/2010/03/how-to-run-external-command.html)[[2]](http://ujihisa.blogspot.com/2010/03/all-about-spawn.html).
|
6
|
+
But ruby 1.8, the legacy version of MRI, is still used on many environments.
|
7
|
+
|
8
|
+
This library provides `spawn()` which is almost perfectly compatible with ruby 1.9's.
|
9
|
+
This library is pure ruby; you don't need to build it.
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
gem install sfl
|
14
|
+
|
15
|
+
## How to use
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'sfl'
|
19
|
+
|
20
|
+
spawn 'ls'
|
21
|
+
|
22
|
+
If your ruby is 1.9, `require 'sfl'` doesn't do anything. If your ruby is 1.8, that defines `spawn`.
|
23
|
+
|
24
|
+
## How compatible this spawn is?
|
25
|
+
|
26
|
+
(I'll put the coverage here later)
|
27
|
+
|
28
|
+
## Misc.
|
29
|
+
|
30
|
+
* At first I tried to use the name `spawn` as this gem library name, but the name was already used. The `spawn` gem library does not mean ruby 1.9's `spawn` at all.
|
31
|
+
* Ruby 1.9's `open3` library, based on `spawn`, is very useful. I would like to port `open3` to ruby 1.8 in my future.
|
32
|
+
|
33
|
+
## Supports
|
34
|
+
|
35
|
+
* (On MacOS) MRI 1.8.6, 1.8.7, 1.9.1, 1.9.2-rc2
|
36
|
+
* (On UNIX) MRI 1.8.6, 1.8.7, 1.9.1, 1.9.2pre
|
37
|
+
* (On Windows) MRI 1.9.1, 1.9.2pre
|
38
|
+
|
39
|
+
Currently there are no supports on:
|
40
|
+
|
41
|
+
* MRI 1.8 on Windows
|
42
|
+
* Other Ruby implementations such as JRuby, Rubinius and MacRuby
|
43
|
+
|
44
|
+
## Authors
|
45
|
+
|
46
|
+
Tatsuhiro Ujihisa
|
47
|
+
<http://ujihisa.blogspot.com/>
|
48
|
+
|
49
|
+
Bernard Lambeau
|
50
|
+
<http://revision-zero.org/>
|
data/spec/sfl_spec.rb
CHANGED
@@ -57,6 +57,34 @@ describe 'Kernel.spawn' do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
context 'with command "echo ahi"' do
|
61
|
+
it 'outputs "ahi" on stdout' do
|
62
|
+
mocker(%q|
|
63
|
+
pid = Kernel.spawn('echo ahi')
|
64
|
+
Process.wait(pid)
|
65
|
+
|).chomp.should == "ahi"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with command "true && echo ahi"' do
|
70
|
+
it 'outputs "ahi" on stdout' do
|
71
|
+
mocker(%q|
|
72
|
+
pid = Kernel.spawn('true && echo ahi')
|
73
|
+
Process.wait(pid)
|
74
|
+
|).chomp.should == "ahi"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with command "false || :"' do
|
79
|
+
it 'does not fail' do
|
80
|
+
mocker(%q[
|
81
|
+
pid = Kernel.spawn('false || :')
|
82
|
+
Process.wait(pid)
|
83
|
+
puts 'ahi' if $?.to_i == 0
|
84
|
+
]).chomp.should == "ahi"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
60
88
|
# The following test is unsound and lead to spec
|
61
89
|
# failures under specific rubies...
|
62
90
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: rspec
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
@@ -33,7 +38,12 @@ dependencies:
|
|
33
38
|
version: 2.4.0
|
34
39
|
type: :development
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.4.0
|
37
47
|
description: Spawn For Ruby 1.8
|
38
48
|
email: ujihisa at gmail.com
|
39
49
|
executables: []
|
@@ -42,6 +52,8 @@ extra_rdoc_files:
|
|
42
52
|
- README.md
|
43
53
|
files:
|
44
54
|
- lib/sfl.rb
|
55
|
+
- spec/mocker.rb
|
56
|
+
- spec/mocker_output.txt
|
45
57
|
- spec/sfl_spec.rb
|
46
58
|
- sfl.gemspec
|
47
59
|
- Rakefile
|
@@ -67,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
79
|
version: '0'
|
68
80
|
requirements: []
|
69
81
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.23
|
71
83
|
signing_key:
|
72
84
|
specification_version: 3
|
73
85
|
summary: Spawn For Ruby 1.8
|