lsl 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/lsl/command/execution.rb +28 -3
- data/lib/lsl/command/single.rb +3 -0
- data/lib/lsl/grammars/base.treetop +1 -1
- data/lib/lsl/grammars/compound_command.treetop +15 -4
- data/lib/lsl/shell.rb +17 -1
- data/lsl.gemspec +1 -1
- data/spec/compound_command_spec.rb +3 -0
- data/spec/shell_spec.rb +5 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -68,8 +68,24 @@ module LSL
|
|
68
68
|
fattr(:args) do
|
69
69
|
command_args + fixed_input_args
|
70
70
|
end
|
71
|
+
def my_eval(ops,str)
|
72
|
+
OpenStruct.new(ops).instance_eval(str)
|
73
|
+
rescue => exp
|
74
|
+
puts "failed #{exp.message}"
|
75
|
+
end
|
71
76
|
fattr(:result) do
|
72
|
-
if
|
77
|
+
if command.eval?
|
78
|
+
res = []
|
79
|
+
if args.empty?
|
80
|
+
res << my_eval(command.raw[1..-2],:args => [], :arg => nil)
|
81
|
+
else
|
82
|
+
args.each_with_expansion do |a|
|
83
|
+
res << my_eval(command.raw[1..-2],:args => a, :arg => a.first)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
#puts res.inspect
|
87
|
+
res
|
88
|
+
elsif obj.respond_to?(command.method)
|
73
89
|
res = obj.send_with_expansion(command.method,*args)
|
74
90
|
#puts "RES #{res.inspect}" if res
|
75
91
|
res
|
@@ -84,7 +100,7 @@ module LSL
|
|
84
100
|
end
|
85
101
|
end
|
86
102
|
class Compound < Base
|
87
|
-
fattr(:command) { shell.parser.parse(command_str).command_hash }
|
103
|
+
fattr(:command) { shell.parser.parse(command_str).andand.command_hash }
|
88
104
|
fattr(:command_executions) do
|
89
105
|
exes = []
|
90
106
|
input_args = lambda { exes.last.andand.result || [] }
|
@@ -96,16 +112,25 @@ module LSL
|
|
96
112
|
exes
|
97
113
|
end
|
98
114
|
def run!
|
115
|
+
if !command
|
116
|
+
puts "can't parse"
|
117
|
+
return
|
118
|
+
end
|
99
119
|
command_executions
|
100
120
|
if command.output_filename
|
101
121
|
::File.create(command.output_filename,result.join("\n"))
|
102
122
|
else
|
103
|
-
puts
|
123
|
+
puts result_str if result
|
104
124
|
end
|
105
125
|
end
|
106
126
|
def result
|
107
127
|
command_executions.last.result
|
108
128
|
end
|
129
|
+
def result_str
|
130
|
+
res = result
|
131
|
+
res = res.join("\n") if res.respond_to?(:join)
|
132
|
+
res
|
133
|
+
end
|
109
134
|
end
|
110
135
|
end
|
111
136
|
end
|
data/lib/lsl/command/single.rb
CHANGED
@@ -3,14 +3,15 @@ module LSL
|
|
3
3
|
include LSL::SingleCommand
|
4
4
|
include LSL::File
|
5
5
|
rule full_command
|
6
|
-
|
6
|
+
some_command (ows "|" ows some_command)* (ows ">" ows filename)? {
|
7
7
|
def filename
|
8
8
|
find_child_node(:filename)
|
9
9
|
end
|
10
10
|
def single_commands
|
11
|
-
|
12
|
-
res = [
|
13
|
-
|
11
|
+
|
12
|
+
res = [some_command.command_hash]
|
13
|
+
#res = [elements.first.command_hash]
|
14
|
+
rest = find_child_nodes(:some_command).map { |x| x.command_hash }
|
14
15
|
#puts "rest #{rest.size}"
|
15
16
|
res + rest
|
16
17
|
end
|
@@ -21,5 +22,15 @@ module LSL
|
|
21
22
|
end
|
22
23
|
}
|
23
24
|
end
|
25
|
+
rule eval_str
|
26
|
+
"{" (!"}" .)+ "}" {
|
27
|
+
def command_hash
|
28
|
+
LSL::Command::Single.new(:raw => text_value, :args => [], :options => {})
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
rule some_command
|
33
|
+
single_command / eval_str
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
data/lib/lsl/shell.rb
CHANGED
@@ -17,9 +17,16 @@ module LSL
|
|
17
17
|
module Inner
|
18
18
|
def echo(*args)
|
19
19
|
#puts args.inspect
|
20
|
-
|
20
|
+
ops = (args.last.kind_of?(Hash) ? args.pop : {})
|
21
|
+
str = args.join(" ")
|
22
|
+
str = str.upcase if ops.has_key?('upper')
|
23
|
+
puts str
|
21
24
|
nil
|
22
25
|
end
|
26
|
+
def echot(*args)
|
27
|
+
echo(*args)
|
28
|
+
echo(*args)
|
29
|
+
end
|
23
30
|
def ls(d=".")
|
24
31
|
ec_array "ls #{d}"
|
25
32
|
end
|
@@ -52,6 +59,15 @@ module LSL
|
|
52
59
|
puts "Exiting"
|
53
60
|
Kernel.exit(*args)
|
54
61
|
end
|
62
|
+
def eval(*args)
|
63
|
+
Kernel.eval(args.join(" "))
|
64
|
+
end
|
65
|
+
def rand
|
66
|
+
Kernel.rand()
|
67
|
+
end
|
68
|
+
def pt(a,b)
|
69
|
+
puts a==b
|
70
|
+
end
|
55
71
|
end
|
56
72
|
include FileUtils
|
57
73
|
include Inner
|
data/lsl.gemspec
CHANGED
data/spec/shell_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe "Shell" do
|
|
14
14
|
end
|
15
15
|
it 'piping' do
|
16
16
|
@shell.run('ls VERSION | pf')
|
17
|
-
$printed.should == ['0.0
|
17
|
+
$printed.should == ['0.1.0']
|
18
18
|
end
|
19
19
|
it 'foo' do
|
20
20
|
#30.times do
|
@@ -32,7 +32,10 @@ describe "Shell" do
|
|
32
32
|
run("remote_call foo | echo")
|
33
33
|
end
|
34
34
|
it 'rake' do
|
35
|
-
run("abc").result.should == "ran"
|
35
|
+
#run("abc").result.should == "ran"
|
36
|
+
end
|
37
|
+
it 'eval' do
|
38
|
+
run("{2 + 2}").result.should == 4
|
36
39
|
end
|
37
40
|
describe 'output redirection' do
|
38
41
|
before do
|