CommandLine 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+
2
+ class Module
3
+ def param_accessor(*symbols)
4
+ symbols.each { |sym|
5
+ self.class_eval %{
6
+ def #{sym}(*val)
7
+ val.empty? ? @#{sym} : @#{sym} = val
8
+ end
9
+ }
10
+ }
11
+ end
12
+ end
data/lib/open4.rb ADDED
@@ -0,0 +1,79 @@
1
+ # stolen directly from Open3::open3.rb!
2
+ #
3
+ # open4.rb: Spawn a program like popen, but with stderr, and pid, too. You might
4
+ # also want to use this if you want to bypass the shell. (By passing multiple
5
+ # args, which IO#popen does not allow)
6
+ #
7
+ # Usage:
8
+ # require "open4"
9
+ #
10
+ # stdin, stdout, stderr, pid = Open4.popen4('nroff -man')
11
+ # or
12
+ # include Open4
13
+ # stdin, stdout, stderr, pid = popen4('nroff -man')
14
+
15
+ module Open4
16
+ #--{{{
17
+ #[stdin, stdout, stderr, pid] = popen4(command);
18
+ def popen4(*cmd)
19
+ #--{{{
20
+ pw = IO::pipe # pipe[0] for read, pipe[1] for write
21
+ pr = IO::pipe
22
+ pe = IO::pipe
23
+
24
+ verbose = $VERBOSE
25
+ begin
26
+ $VERBOSE = nil # shut up warning about forking in threads, world writable
27
+ # dirs, etc
28
+ cid =
29
+ fork{
30
+ # child
31
+ pw[1].close
32
+ STDIN.reopen(pw[0])
33
+ pw[0].close
34
+
35
+ pr[0].close
36
+ STDOUT.reopen(pr[1])
37
+ pr[1].close
38
+
39
+ pe[0].close
40
+ STDERR.reopen(pe[1])
41
+ pe[1].close
42
+
43
+ STDOUT.sync = true
44
+ STDERR.sync = true
45
+
46
+ exec(*cmd)
47
+ }
48
+ ensure
49
+ $VERBOSE = verbose
50
+ end
51
+
52
+ pw[0].close
53
+ pr[1].close
54
+ pe[1].close
55
+ pi = [pw[1], pr[0], pe[0]]
56
+ pw[1].sync = true
57
+ if defined? yield
58
+ begin
59
+ yield(cid, *pi)
60
+ return(Process::waitpid2(cid).last)
61
+ ensure
62
+ pi.each{|p| p.close unless p.closed?}
63
+ end
64
+ end
65
+ [cid, pw[1], pr[0], pe[0]]
66
+ #--}}}
67
+ end
68
+ alias open4 popen4
69
+ module_function :popen4
70
+ module_function :open4
71
+ #--}}}
72
+ end
73
+
74
+ if $0 == __FILE__
75
+ status = Open4::popen4('sh'){|cid,i,o,e|i.puts 'echo 42';i.close; puts o.read;}
76
+ p [status]
77
+ p status.exitstatus
78
+ p status == 0
79
+ end
@@ -0,0 +1,58 @@
1
+
2
+ module Test
3
+
4
+ module Unit
5
+
6
+ class TestCase
7
+ require 'open4'
8
+ def run_app(app, *args)
9
+ cmd = [app, args].flatten.join(" ")
10
+ out = nil
11
+ err = nil
12
+ status = Open4.popen4(cmd) { |cid, stdin, stdout, stderr|
13
+ out = stdout.read
14
+ err = stderr.read
15
+ stdin.close
16
+ }
17
+ [out, err, status]
18
+ end
19
+
20
+ def assert_success(app, *args)
21
+ args.compact!
22
+ out, err, status = run_app(app, args)
23
+ assert_equal(true, status.success?,
24
+ "Failure running #{[app,args].delete_if { |i| i.empty? }.join(" ")} "+
25
+ "with error(s):\n => stderr: '#{err}'\n => stdout: '#{out}'.")
26
+ yield(out, err, status) if block_given?
27
+ end
28
+
29
+ def assert_failure(app, *args)
30
+ out, err, status = run_app(app, args)
31
+ assert_equal(false, status.success?,
32
+ "No failure running #{[app,args].delete_if { |i| i.empty? }.join(" ")}.")
33
+ yield(out, err, status) if block_given?
34
+ end
35
+
36
+ def assert_coredump(app, *args)
37
+ out, err, status = run_app(app, args)
38
+ assert_equal(true, status.coredump?,
39
+ "Running #{[app,args].delete_if { |i| i.empty? }.join(" ")} did not coredump.")
40
+ yield(out, err, status) if block_given?
41
+ end
42
+ def assert_no_coredump(app, *args)
43
+ out, err, status = run_app(app, args)
44
+ assert_equal(false, status.coredump?,
45
+ "Running #{[app,args].delete_if { |i| i.empty? }.join(" ")} caused coredump.")
46
+ yield(out, err, status) if block_given?
47
+ end
48
+
49
+ def assert_stopped(app, *args)
50
+ out, err, status = run_app(app, args)
51
+ assert_equal(true, status.stopped?,
52
+ "Running #{[app,args].delete_if { |i| i.empty? }.join(" ")} not stopped.")
53
+ yield(out, err, status) if block_given?
54
+ end
55
+
56
+ end
57
+ end#module Unit
58
+ end#module Test
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.10
3
+ specification_version: 1
4
+ name: CommandLine
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.6.0
7
+ date: 2005-06-24
8
+ summary: Tools to facilitate creation of command line applications and flexible parsing of command line options.
9
+ require_paths:
10
+ - lib
11
+ email: commandline@freeze.org
12
+ homepage: http://rubyforge.org/projects/optionparser/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: commandline
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ authors:
28
+ - Jim Freeze
29
+ files:
30
+ - docs/index.html
31
+ - lib/commandline
32
+ - lib/commandline.rb
33
+ - lib/open4.rb
34
+ - lib/test
35
+ - lib/commandline/application
36
+ - lib/commandline/application.rb
37
+ - lib/commandline/optionparser
38
+ - lib/commandline/optionparser.rb
39
+ - lib/commandline/text
40
+ - lib/commandline/utils.rb
41
+ - lib/commandline/optionparser/option.rb
42
+ - lib/commandline/optionparser/optiondata.rb
43
+ - lib/commandline/optionparser/optionparser.rb
44
+ - lib/commandline/text/format.rb
45
+ - lib/test/unit
46
+ - lib/test/unit/systemtest.rb
47
+ - README
48
+ - LICENSE
49
+ test_files: []
50
+ rdoc_options: []
51
+ extra_rdoc_files:
52
+ - README
53
+ - LICENSE
54
+ executables: []
55
+ extensions: []
56
+ requirements: []
57
+ dependencies: []