sfl 1.1 → 1.2
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/lib/sfl.rb +70 -24
- metadata +15 -4
data/lib/sfl.rb
CHANGED
@@ -1,31 +1,46 @@
|
|
1
1
|
class SFL
|
2
2
|
attr_reader :command, :environment, :argument, :option
|
3
3
|
|
4
|
+
# SFL.new('ls', '-a') becomes
|
5
|
+
# @environment = {}
|
6
|
+
# @command = ['ls', 'ls']
|
7
|
+
# @argument = ['-a']
|
8
|
+
# @option = {}
|
4
9
|
def initialize(*cmdandarg)
|
5
10
|
raise ArgumentError if cmdandarg.size == 0
|
6
11
|
cmdandarg = cmdandarg.dup
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
13
|
+
@environment =
|
14
|
+
if Hash === cmdandarg.first
|
15
|
+
cmdandarg.shift
|
16
|
+
else
|
17
|
+
{}
|
18
|
+
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
@option =
|
21
|
+
if Hash === cmdandarg.last
|
22
|
+
cmdandarg.pop
|
23
|
+
else
|
24
|
+
{}
|
25
|
+
end
|
21
26
|
|
22
|
-
if
|
23
|
-
|
27
|
+
if cmdandarg.size == 1
|
28
|
+
cmdandarg = cmdandarg.first
|
29
|
+
if String === cmdandarg
|
30
|
+
cmd, *arg = self.class.parse_command_with_arg(cmdandarg)
|
31
|
+
@command = [cmd, cmd]
|
32
|
+
@argument = arg
|
33
|
+
else
|
34
|
+
@command = cmdandarg
|
35
|
+
@argument = []
|
36
|
+
end
|
24
37
|
else
|
25
|
-
|
38
|
+
# 'ls', '.' -> [['ls', 'ls'], '.']
|
39
|
+
cmd = cmdandarg.shift
|
40
|
+
cmd = (String === cmd) ? [cmd, cmd] : cmd
|
41
|
+
@command = cmd
|
42
|
+
@argument = cmdandarg
|
26
43
|
end
|
27
|
-
|
28
|
-
@argument = cmdandarg
|
29
44
|
end
|
30
45
|
|
31
46
|
def run
|
@@ -98,17 +113,48 @@ class SFL
|
|
98
113
|
ast
|
99
114
|
end
|
100
115
|
end
|
116
|
+
|
117
|
+
def parse_command_with_arg(x)
|
118
|
+
in_squote = false
|
119
|
+
in_dquote = false
|
120
|
+
tmp = ''
|
121
|
+
cmdargs = []
|
122
|
+
x.strip.split(//).each do |c|
|
123
|
+
case c
|
124
|
+
when '"'
|
125
|
+
if in_dquote
|
126
|
+
in_dquote = false
|
127
|
+
else
|
128
|
+
in_dquote = true
|
129
|
+
end
|
130
|
+
when "'"
|
131
|
+
if in_squote
|
132
|
+
in_squote = false
|
133
|
+
else
|
134
|
+
in_squote = true
|
135
|
+
end
|
136
|
+
when ' '
|
137
|
+
if in_dquote || in_squote
|
138
|
+
tmp << ' '
|
139
|
+
else
|
140
|
+
cmdargs << tmp
|
141
|
+
tmp = ''
|
142
|
+
end
|
143
|
+
else
|
144
|
+
tmp << c
|
145
|
+
end
|
146
|
+
end
|
147
|
+
cmdargs << tmp
|
148
|
+
end
|
101
149
|
end
|
102
150
|
end
|
103
151
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
152
|
+
def spawn(*x)
|
153
|
+
SFL.new(*x).run
|
154
|
+
end
|
108
155
|
|
109
|
-
|
110
|
-
|
111
|
-
end
|
156
|
+
def Process.spawn(*x)
|
157
|
+
SFL.new(*x).run
|
112
158
|
end
|
113
159
|
|
114
160
|
if RUBY_VERSION <= '1.8.6'
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: "1.2"
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- ujihisa
|
@@ -34,21 +39,27 @@ rdoc_options: []
|
|
34
39
|
require_paths:
|
35
40
|
- lib
|
36
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
37
43
|
requirements:
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
40
49
|
version: "0"
|
41
|
-
version:
|
42
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
43
52
|
requirements:
|
44
53
|
- - ">="
|
45
54
|
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
46
58
|
version: "0"
|
47
|
-
version:
|
48
59
|
requirements: []
|
49
60
|
|
50
61
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.3.
|
62
|
+
rubygems_version: 1.3.7
|
52
63
|
signing_key:
|
53
64
|
specification_version: 3
|
54
65
|
summary: Spawn For Ruby 1.8
|