shr 0.1.2 → 0.1.3
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/shr/command.rb +10 -4
- data/lib/shr/shell.rb +11 -21
- data/lib/shr/version.rb +1 -1
- data/spec/lib/shr/command_spec.rb +2 -1
- data/spec/lib/shr/shell_spec.rb +1 -1
- data/spec/lib/shr/shell_win_spec.rb +1 -1
- metadata +2 -3
- data/.swp +0 -0
data/lib/shr/command.rb
CHANGED
@@ -31,11 +31,17 @@ module Shr
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# xxx
|
34
|
-
def run(environment)
|
35
|
-
|
34
|
+
def run(environment, command_out)
|
35
|
+
io_r, io_w = IO.pipe
|
36
|
+
options = { :out => io_w }
|
37
|
+
options[:in] = command_out if command_out
|
38
|
+
options.merge!(environment)
|
39
|
+
|
40
|
+
pid = spawn(self.to_s, options)
|
36
41
|
watcher = Process.detach(pid)
|
37
|
-
|
38
|
-
|
42
|
+
io_w.close
|
43
|
+
|
44
|
+
[io_r, watcher]
|
39
45
|
end
|
40
46
|
|
41
47
|
# xxx
|
data/lib/shr/shell.rb
CHANGED
@@ -5,7 +5,7 @@ module Shr
|
|
5
5
|
class Shell
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@commands = []
|
9
9
|
end
|
10
10
|
|
11
11
|
def method_missing(name, *args)
|
@@ -25,7 +25,7 @@ module Shr
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def inspect
|
28
|
-
command_line = @
|
28
|
+
command_line = @commands.join(' | ').strip
|
29
29
|
force
|
30
30
|
res = "#<Shr::Shell>"
|
31
31
|
res << "<:command => #{command_line}>" if command_line.size > 0
|
@@ -68,34 +68,24 @@ module Shr
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def delay(command)
|
71
|
-
@
|
71
|
+
@commands << command
|
72
72
|
end
|
73
73
|
|
74
|
-
# xxx
|
75
74
|
def force(args={})
|
76
|
-
return if @
|
75
|
+
return if @commands.empty?
|
77
76
|
|
78
|
-
@
|
79
|
-
|
80
|
-
environment = { :out => io_w }
|
81
|
-
environment[:in] = @command_out if @command_out
|
82
|
-
environment.merge!(args)
|
83
|
-
|
84
|
-
watcher = promise.run(environment)
|
85
|
-
|
86
|
-
@command_out = io_r
|
87
|
-
@wait_thread = watcher
|
77
|
+
@commands.each do |command|
|
78
|
+
@command_out, @wait_thread = command.run(args, @command_out)
|
88
79
|
end
|
89
|
-
|
90
|
-
@
|
80
|
+
@wait_thread.join
|
81
|
+
@commands.clear
|
91
82
|
end
|
92
83
|
|
93
|
-
# xxx
|
94
84
|
def force!
|
95
|
-
return if @
|
85
|
+
return if @commands.empty?
|
96
86
|
|
97
|
-
@
|
98
|
-
@
|
87
|
+
@commands[-1].run!
|
88
|
+
@commands.clear
|
99
89
|
end
|
100
90
|
end
|
101
91
|
end
|
data/lib/shr/version.rb
CHANGED
data/spec/lib/shr/shell_spec.rb
CHANGED
@@ -84,7 +84,7 @@ module Shr
|
|
84
84
|
it 'redirecs result of command to file' do
|
85
85
|
tempfile = Tempfile.new('temp')
|
86
86
|
sh.pwd.redirect_to(tempfile.path)
|
87
|
-
sh.cat(tempfile.path).to_s.should eq(`pwd`)
|
87
|
+
sh.cat.redirect_from(tempfile.path).to_s.should eq(`pwd`)
|
88
88
|
tempfile.close!
|
89
89
|
end
|
90
90
|
end
|
@@ -67,7 +67,7 @@ module Shr
|
|
67
67
|
it 'redirecs result of command to file' do
|
68
68
|
tempfile = Tempfile.new('temp')
|
69
69
|
sh.chdir.redirect_to(tempfile.path)
|
70
|
-
sh.
|
70
|
+
sh.more.redirect_from(tempfile.path).to_s.should eq(`chdir`)
|
71
71
|
tempfile.close!
|
72
72
|
end
|
73
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: os
|
@@ -35,7 +35,6 @@ extensions: []
|
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
|
-
- .swp
|
39
38
|
- Gemfile
|
40
39
|
- Guardfile
|
41
40
|
- LICENSE.md
|
data/.swp
DELETED
Binary file
|