mux 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +37 -0
- data/bin/mux +3 -2
- data/doc/mux.1.gz +0 -0
- data/lib/mux.rb +23 -34
- data/mux.gemspec +17 -0
- data/test/executable_test.rb +51 -0
- metadata +7 -3
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
PKG_NAME = 'mux'
|
6
|
+
PKG_VERSION = '0.0.3'
|
7
|
+
|
8
|
+
desc "Default task"
|
9
|
+
task :default => [:test]
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.pattern = 'test/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
t.warning = true
|
15
|
+
end
|
16
|
+
|
17
|
+
GEM_SPEC = eval(File.read("#{File.dirname(__FILE__)}/#{PKG_NAME}.gemspec"))
|
18
|
+
|
19
|
+
Rake::GemPackageTask.new(GEM_SPEC) do |p|
|
20
|
+
p.gem_spec = GEM_SPEC
|
21
|
+
p.need_tar = true
|
22
|
+
p.need_zip = true
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Clean up generated files"
|
26
|
+
task :clean do
|
27
|
+
rm_rf "pkg"
|
28
|
+
rm_rf "doc/mux.1.gz"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Zip manpage"
|
32
|
+
task :man do
|
33
|
+
sh "gzip -c doc/mux.1 >doc/mux.1.gz"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Build and package for release"
|
37
|
+
task :release => [:man, :package]
|
data/bin/mux
CHANGED
@@ -28,7 +28,8 @@
|
|
28
28
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
29
29
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30
30
|
# SOFTWARE.
|
31
|
-
require 'rubygems'
|
31
|
+
#require 'rubygems'
|
32
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
32
33
|
require 'mux'
|
33
34
|
|
34
|
-
Mux.run(ARGV)
|
35
|
+
Mux.new.run(ARGV)
|
data/doc/mux.1.gz
ADDED
Binary file
|
data/lib/mux.rb
CHANGED
@@ -30,47 +30,39 @@
|
|
30
30
|
require 'optparse'
|
31
31
|
require 'ostruct'
|
32
32
|
|
33
|
-
class Mux
|
34
|
-
|
33
|
+
class Mux
|
34
|
+
|
35
|
+
M = { :pipe => {:class => 'IO', :method => 'popen', :mode => 'w'},
|
36
|
+
:funnel => {:class => 'File', :method => 'open', :mode => 'w'},
|
37
|
+
:append => {:class => 'File', :method => 'open', :mode => 'a'} }
|
38
|
+
|
39
|
+
def run(args)
|
35
40
|
options = Mux::Options.parse(args)
|
36
41
|
|
37
|
-
streams = []
|
42
|
+
streams = options.to_stdout ? [$stdout] : []
|
38
43
|
|
39
|
-
|
40
|
-
|
44
|
+
# this is silly and rather non-intuitive (at least tonight), but is fun
|
45
|
+
# nonetheless... i'll keep it around for a while and see what i think.
|
46
|
+
# ps. IT TOTALLY WORKS!
|
47
|
+
M.each_key do |k|
|
48
|
+
o = lambda { eval("options.#{k}s") }
|
49
|
+
streams.concat(open_streams(o.call, k)) if o.call
|
41
50
|
end
|
42
|
-
|
43
|
-
streams.concat(open_streams(options.pipes, 'pipe'))
|
44
|
-
streams.concat(open_streams(options.funnels, 'funnel'))
|
45
|
-
streams.concat(open_streams(options.appends, 'append'))
|
46
51
|
|
47
|
-
|
48
|
-
streams.each
|
49
|
-
stream.puts buffer
|
50
|
-
end
|
52
|
+
$stdin.each_line do |b|
|
53
|
+
streams.each {|s| s.write b }
|
51
54
|
end
|
52
55
|
|
53
|
-
streams.each
|
54
|
-
stream.close
|
55
|
-
end
|
56
|
-
|
56
|
+
streams.each {|s| s.close }
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
|
61
|
-
targets.each do |target|
|
62
|
-
case type
|
63
|
-
when 'pipe'
|
64
|
-
handles << IO.popen(target, 'w')
|
65
|
-
when 'funnel'
|
66
|
-
handles << File.open(target, 'w')
|
67
|
-
when 'append'
|
68
|
-
handles << File.open(target, 'a')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
handles
|
59
|
+
def open_streams(targets, type)
|
60
|
+
targets.map {|t| open_stream(t,type) }
|
72
61
|
end
|
73
62
|
|
63
|
+
def open_stream(target, type)
|
64
|
+
eval("#{M[type][:class]}.#{M[type][:method]}(target,'#{M[type][:mode]}')")
|
65
|
+
end
|
74
66
|
end
|
75
67
|
|
76
68
|
class Mux::Options
|
@@ -78,9 +70,6 @@ class Mux::Options
|
|
78
70
|
options = OpenStruct.new
|
79
71
|
options.verbose = false
|
80
72
|
options.to_stdout = false
|
81
|
-
options.pipes = []
|
82
|
-
options.appends = []
|
83
|
-
options.funnels = []
|
84
73
|
|
85
74
|
opts = OptionParser.new do |opts|
|
86
75
|
opts.banner = "Usage: mux [options]"
|
@@ -118,6 +107,6 @@ class Mux::Options
|
|
118
107
|
end
|
119
108
|
|
120
109
|
opts.parse!(args)
|
121
|
-
options
|
110
|
+
return options
|
122
111
|
end
|
123
112
|
end
|
data/mux.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'mux'
|
6
|
+
s.version = PKG_VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.summary = 'tee(1) on crack'
|
9
|
+
s.files = FileList['Rakefile', 'bin/mux', 'lib/*.rb', 'README', 'doc/mux.1.gz', 'test/*.rb', 'mux.gemspec']
|
10
|
+
s.require_path = 'lib'
|
11
|
+
s.autorequire = 'mux'
|
12
|
+
s.bindir = 'bin'
|
13
|
+
s.executables << 'mux'
|
14
|
+
s.author = 'Jerome Harrington'
|
15
|
+
s.email = 'jharrington@awk-fu.com'
|
16
|
+
s.homepage = 'http://www.awk-fu.com/software/mux'
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mux'
|
5
|
+
|
6
|
+
class Mux::ExecutableTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
MUX = 'ruby ' + File.join(File.dirname(__FILE__), '..', 'bin', 'mux')
|
9
|
+
|
10
|
+
OUT_FILE = '/tmp/mux_executable_test.txt'
|
11
|
+
|
12
|
+
def setup
|
13
|
+
remove_out_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
remove_out_file
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove_out_file
|
21
|
+
if File.exists?(OUT_FILE)
|
22
|
+
File.delete(OUT_FILE)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_pipe
|
27
|
+
r = `echo "blah" | #{MUX} -p 'cat'`
|
28
|
+
assert_equal "blah\n", r
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_stdout
|
32
|
+
r = `echo "blah" | #{MUX} -s`
|
33
|
+
assert_equal "blah\n", r
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_funnel
|
37
|
+
r = `echo "blah" | #{MUX} -f #{OUT_FILE}`
|
38
|
+
r = File.read(OUT_FILE)
|
39
|
+
assert_equal "blah\n", r
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_append
|
43
|
+
2.times do
|
44
|
+
`echo "blah" | #{MUX} -a #{OUT_FILE}`
|
45
|
+
end
|
46
|
+
|
47
|
+
r = File.read(OUT_FILE)
|
48
|
+
assert_equal "blah\nblah\n", r
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.1
|
3
3
|
specification_version: 1
|
4
4
|
name: mux
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date:
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2007-02-08 00:00:00 -05:00
|
8
8
|
summary: tee(1) on crack
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,9 +29,13 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Jerome Harrington
|
31
31
|
files:
|
32
|
+
- Rakefile
|
32
33
|
- bin/mux
|
33
34
|
- lib/mux.rb
|
34
35
|
- README
|
36
|
+
- doc/mux.1.gz
|
37
|
+
- test/executable_test.rb
|
38
|
+
- mux.gemspec
|
35
39
|
test_files: []
|
36
40
|
|
37
41
|
rdoc_options: []
|