ruby-lint 0.0.1a → 0.0.1a1

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.
Files changed (77) hide show
  1. data/.yardopts +1 -1
  2. data/MANIFEST +65 -62
  3. data/README.md +114 -13
  4. data/bin/ruby-lint +6 -0
  5. data/lib/ruby-lint.rb +36 -0
  6. data/lib/{rlint → ruby-lint}/analyze/coding_style.rb +32 -32
  7. data/lib/{rlint → ruby-lint}/analyze/definitions.rb +13 -13
  8. data/lib/{rlint → ruby-lint}/analyze/method_validation.rb +5 -5
  9. data/lib/{rlint → ruby-lint}/analyze/shadowing_variables.rb +5 -5
  10. data/lib/{rlint → ruby-lint}/analyze/undefined_variables.rb +7 -7
  11. data/lib/{rlint → ruby-lint}/analyze/unused_variables.rb +6 -6
  12. data/lib/{rlint → ruby-lint}/callback.rb +11 -11
  13. data/lib/{rlint → ruby-lint}/cli.rb +17 -17
  14. data/lib/{rlint → ruby-lint}/constant_importer.rb +18 -8
  15. data/lib/{rlint → ruby-lint}/definition.rb +10 -10
  16. data/lib/{rlint → ruby-lint}/formatter/text.rb +6 -6
  17. data/lib/{rlint → ruby-lint}/helper/definition_resolver.rb +11 -11
  18. data/lib/{rlint → ruby-lint}/helper/scoping.rb +14 -14
  19. data/lib/{rlint → ruby-lint}/iterator.rb +22 -22
  20. data/lib/{rlint → ruby-lint}/options.rb +9 -9
  21. data/lib/{rlint → ruby-lint}/parser.rb +111 -111
  22. data/lib/{rlint → ruby-lint}/parser_error.rb +3 -3
  23. data/lib/{rlint → ruby-lint}/report.rb +8 -8
  24. data/lib/{rlint → ruby-lint}/token/assignment_token.rb +4 -4
  25. data/lib/{rlint → ruby-lint}/token/begin_rescue_token.rb +7 -7
  26. data/lib/{rlint → ruby-lint}/token/block_token.rb +12 -3
  27. data/lib/{rlint → ruby-lint}/token/case_token.rb +5 -5
  28. data/lib/{rlint → ruby-lint}/token/class_token.rb +3 -3
  29. data/lib/{rlint → ruby-lint}/token/method_definition_token.rb +8 -8
  30. data/lib/{rlint → ruby-lint}/token/method_token.rb +9 -7
  31. data/lib/{rlint → ruby-lint}/token/parameters_token.rb +6 -6
  32. data/lib/{rlint → ruby-lint}/token/regexp_token.rb +2 -2
  33. data/lib/{rlint → ruby-lint}/token/statement_token.rb +6 -6
  34. data/lib/{rlint → ruby-lint}/token/token.rb +8 -6
  35. data/lib/{rlint → ruby-lint}/token/variable_token.rb +3 -3
  36. data/lib/ruby-lint/version.rb +3 -0
  37. data/ruby-lint.gemspec +5 -5
  38. data/spec/benchmarks/memory.rb +7 -7
  39. data/spec/benchmarks/parse_parser.rb +5 -5
  40. data/spec/fixtures/stdlib/un.rb +348 -0
  41. data/spec/helper.rb +3 -1
  42. data/spec/{rlint → ruby-lint}/analyze/coding_style.rb +30 -30
  43. data/spec/ruby-lint/analyze/complex/un.rb +29 -0
  44. data/spec/{rlint → ruby-lint}/analyze/definitions/classes.rb +25 -25
  45. data/spec/{rlint → ruby-lint}/analyze/definitions/methods.rb +22 -22
  46. data/spec/{rlint → ruby-lint}/analyze/definitions/modules.rb +42 -42
  47. data/spec/{rlint → ruby-lint}/analyze/definitions/variables.rb +27 -27
  48. data/spec/{rlint → ruby-lint}/analyze/method_validation.rb +31 -31
  49. data/spec/{rlint → ruby-lint}/analyze/shadowing_variables.rb +6 -6
  50. data/spec/{rlint → ruby-lint}/analyze/undefined_variables.rb +37 -37
  51. data/spec/{rlint → ruby-lint}/analyze/unused_variables.rb +21 -21
  52. data/spec/{rlint → ruby-lint}/callback.rb +7 -7
  53. data/spec/{rlint → ruby-lint}/constant_importer.rb +6 -6
  54. data/spec/{rlint → ruby-lint}/definition.rb +25 -25
  55. data/spec/{rlint → ruby-lint}/formatter/text.rb +4 -4
  56. data/spec/{rlint → ruby-lint}/iterator.rb +38 -38
  57. data/spec/{rlint → ruby-lint}/parser/arrays.rb +28 -28
  58. data/spec/{rlint → ruby-lint}/parser/classes.rb +23 -23
  59. data/spec/{rlint → ruby-lint}/parser/errors.rb +4 -4
  60. data/spec/{rlint → ruby-lint}/parser/hashes.rb +24 -24
  61. data/spec/{rlint → ruby-lint}/parser/methods.rb +50 -50
  62. data/spec/{rlint → ruby-lint}/parser/modules.rb +8 -8
  63. data/spec/{rlint → ruby-lint}/parser/objects.rb +8 -8
  64. data/spec/{rlint → ruby-lint}/parser/operators.rb +14 -14
  65. data/spec/{rlint → ruby-lint}/parser/procs.rb +26 -26
  66. data/spec/{rlint → ruby-lint}/parser/ranges.rb +9 -9
  67. data/spec/{rlint → ruby-lint}/parser/regexp.rb +5 -5
  68. data/spec/{rlint → ruby-lint}/parser/scalars.rb +17 -17
  69. data/spec/{rlint → ruby-lint}/parser/statements.rb +94 -94
  70. data/spec/{rlint → ruby-lint}/parser/variables.rb +37 -37
  71. data/spec/{rlint → ruby-lint}/report.rb +4 -4
  72. data/task/manifest.rake +8 -0
  73. data/task/test.rake +1 -1
  74. metadata +69 -66
  75. data/bin/rlint +0 -6
  76. data/lib/rlint.rb +0 -36
  77. data/lib/rlint/version.rb +0 -3
@@ -1,4 +1,4 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Token
3
3
  ##
4
4
  # Generic token class used for data that doesn't require its own specific
@@ -8,7 +8,7 @@ module Rlint
8
8
  #
9
9
  class Token
10
10
  ##
11
- # Hash containing various Ripper types and the Rlint types to use
11
+ # Hash containing various Ripper types and the RubyLint types to use
12
12
  # instead.
13
13
  #
14
14
  # @since 2012-07-29
@@ -41,7 +41,7 @@ module Rlint
41
41
  # attribute is set to the token for the variable's value.
42
42
  #
43
43
  # @since 2012-07-29
44
- # @return [Rlint::Token::Token]
44
+ # @return [RubyLint::Token::Token]
45
45
  #
46
46
  attr_accessor :value
47
47
 
@@ -87,7 +87,7 @@ module Rlint
87
87
 
88
88
  ##
89
89
  # The name of the event to call when iterating over an AST. Set to the
90
- # value of {Rlint::Token::Token#type} unless specified otherwise.
90
+ # value of {RubyLint::Token::Token#type} unless specified otherwise.
91
91
  #
92
92
  # @return [Symbol]
93
93
  #
@@ -103,6 +103,8 @@ module Rlint
103
103
  # corresponding public getter mehtod to be set.
104
104
  #
105
105
  def initialize(options = {})
106
+ @line, @column = 0, 0
107
+
106
108
  options.each do |key, value|
107
109
  if respond_to?(key)
108
110
  instance_variable_set("@#{key}", value)
@@ -136,7 +138,7 @@ module Rlint
136
138
 
137
139
  ##
138
140
  # Returns an array containing all the child nodes that can be iterated by
139
- # {Rlint::Iterator}.
141
+ # {RubyLint::Iterator}.
140
142
  #
141
143
  # @return [Array]
142
144
  #
@@ -159,4 +161,4 @@ module Rlint
159
161
  end
160
162
  end # Token
161
163
  end # Token
162
- end # Rlint
164
+ end # RubyLint
@@ -1,11 +1,11 @@
1
- module Rlint
1
+ module RubyLint
2
2
  module Token
3
3
  ##
4
4
  # Token class used for storing information about variable references.
5
5
  #
6
6
  class VariableToken < Token
7
7
  ##
8
- # @see Rlint::Token::Token#initialize
8
+ # @see RubyLint::Token::Token#initialize
9
9
  #
10
10
  def initialize(*args)
11
11
  super
@@ -15,4 +15,4 @@ module Rlint
15
15
  end
16
16
  end # VariableToken
17
17
  end # Token
18
- end # Rlint
18
+ end # RubyLint
@@ -0,0 +1,3 @@
1
+ module RubyLint
2
+ VERSION = '0.0.1a1'
3
+ end # RubyLint
data/ruby-lint.gemspec CHANGED
@@ -1,15 +1,15 @@
1
- require File.expand_path('../lib/rlint/version', __FILE__)
1
+ require File.expand_path('../lib/ruby-lint/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ruby-lint'
5
- s.version = Rlint::VERSION
6
- s.date = '2012-11-12'
5
+ s.version = RubyLint::VERSION
6
+ s.date = '2012-11-13'
7
7
  s.authors = ['Yorick Peterse']
8
8
  s.email = 'yorickpeterse@gmail.com'
9
9
  s.summary = 'Static code analysis tool and linter for Ruby'
10
- s.homepage = 'https://github.com/yorickpeterse/rlint/'
10
+ s.homepage = 'https://github.com/yorickpeterse/ruby-lint/'
11
11
  s.description = s.summary
12
- s.executables = ['rlint']
12
+ s.executables = ['ruby-lint']
13
13
 
14
14
  s.files = File.read(File.expand_path('../MANIFEST', __FILE__)).split("\n")
15
15
 
@@ -1,6 +1,6 @@
1
- require File.expand_path('../../../lib/rlint', __FILE__)
1
+ require File.expand_path('../../../lib/ruby-lint', __FILE__)
2
2
 
3
- # This file benchmarks the memory increase after parsing a particular Rlint
3
+ # This file benchmarks the memory increase after parsing a particular RubyLint
4
4
  # file and performing code analysis on the resulting tokens.
5
5
  #
6
6
  # For each iteration (the amount is set in the "AMOUNT" environment variable)
@@ -21,16 +21,16 @@ end
21
21
 
22
22
  memory_kb = 0.0
23
23
  amount = ENV['AMOUNT'] ? ENV['AMOUNT'].to_i : 100
24
- path = File.expand_path('../../../lib/rlint/parser.rb', __FILE__)
24
+ path = File.expand_path('../../../lib/ruby-lint/parser.rb', __FILE__)
25
25
  code = File.read(path, File.size(path))
26
26
 
27
27
  amount.times do
28
28
  memory_kb += benchmark_memory do
29
- tokens = Rlint::Parser.new(code, path).parse
30
- iterator = Rlint::Iterator.new
29
+ tokens = RubyLint::Parser.new(code, path).parse
30
+ iterator = RubyLint::Iterator.new
31
31
 
32
- iterator.bind(Rlint::Analyze::CodingStyle)
33
- iterator.bind(Rlint::Analyze::Definitions)
32
+ iterator.bind(RubyLint::Analyze::CodingStyle)
33
+ iterator.bind(RubyLint::Analyze::Definitions)
34
34
 
35
35
  iterator.run(tokens)
36
36
  end
@@ -1,16 +1,16 @@
1
- # This file runs a simple benchmark to see how fast (or slow) Rlint is.
1
+ # This file runs a simple benchmark to see how fast (or slow) RubyLint is.
2
2
  # It benchmarks how long it takes to parse the main parser file
3
- # (lib/rlint/parser.rb) itself.
4
- require File.expand_path('../../../lib/rlint', __FILE__)
3
+ # (lib/ruby-lint/parser.rb) itself.
4
+ require File.expand_path('../../../lib/ruby-lint', __FILE__)
5
5
  require 'benchmark'
6
6
 
7
- code = File.read(File.expand_path('../../../lib/rlint/parser.rb', __FILE__))
7
+ code = File.read(File.expand_path('../../../lib/ruby-lint/parser.rb', __FILE__))
8
8
  amount = ENV['AMOUNT'] ? ENV['AMOUNT'].to_i : 100
9
9
 
10
10
  Benchmark.bmbm(40) do |bench|
11
11
  bench.report "Parse parser.rb #{amount} times" do
12
12
  amount.times do
13
- Rlint::Parser.new(code).parse
13
+ RubyLint::Parser.new(code).parse
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,348 @@
1
+ #
2
+ # = un.rb
3
+ #
4
+ # Copyright (c) 2003 WATANABE Hirofumi <eban@ruby-lang.org>
5
+ #
6
+ # This program is free software.
7
+ # You can distribute/modify this program under the same terms of Ruby.
8
+ #
9
+ # == Utilities to replace common UNIX commands in Makefiles etc
10
+ #
11
+ # == SYNOPSIS
12
+ #
13
+ # ruby -run -e cp -- [OPTION] SOURCE DEST
14
+ # ruby -run -e ln -- [OPTION] TARGET LINK_NAME
15
+ # ruby -run -e mv -- [OPTION] SOURCE DEST
16
+ # ruby -run -e rm -- [OPTION] FILE
17
+ # ruby -run -e mkdir -- [OPTION] DIRS
18
+ # ruby -run -e rmdir -- [OPTION] DIRS
19
+ # ruby -run -e install -- [OPTION] SOURCE DEST
20
+ # ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
21
+ # ruby -run -e touch -- [OPTION] FILE
22
+ # ruby -run -e wait_writable -- [OPTION] FILE
23
+ # ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
24
+ # ruby -run -e httpd -- [OPTION] DocumentRoot
25
+ # ruby -run -e help [COMMAND]
26
+
27
+ require "fileutils"
28
+ require "optparse"
29
+
30
+ module FileUtils
31
+ # @fileutils_label = ""
32
+ @fileutils_output = $stdout
33
+ end
34
+
35
+ def setup(options = "", *long_options)
36
+ opt_hash = {}
37
+ argv = []
38
+ OptionParser.new do |o|
39
+ options.scan(/.:?/) do |s|
40
+ opt_name = s.delete(":").intern
41
+ o.on("-" + s.tr(":", " ")) do |val|
42
+ opt_hash[opt_name] = val
43
+ end
44
+ end
45
+ long_options.each do |s|
46
+ opt_name, arg_name = s.split(/(?=[\s=])/, 2)
47
+ opt_name.sub!(/\A--/, '')
48
+ s = "--#{opt_name.gsub(/([A-Z]+|[a-z])([A-Z])/, '\1-\2').downcase}#{arg_name}"
49
+ puts "#{opt_name}=>#{s}" if $DEBUG
50
+ opt_name = opt_name.intern
51
+ o.on(s) do |val|
52
+ opt_hash[opt_name] = val
53
+ end
54
+ end
55
+ o.on("-v") do opt_hash[:verbose] = true end
56
+ o.order!(ARGV) do |x|
57
+ if /[*?\[{]/ =~ x
58
+ argv.concat(Dir[x])
59
+ else
60
+ argv << x
61
+ end
62
+ end
63
+ end
64
+ yield argv, opt_hash
65
+ end
66
+
67
+ ##
68
+ # Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY
69
+ #
70
+ # ruby -run -e cp -- [OPTION] SOURCE DEST
71
+ #
72
+ # -p preserve file attributes if possible
73
+ # -r copy recursively
74
+ # -v verbose
75
+ #
76
+
77
+ def cp
78
+ setup("pr") do |argv, options|
79
+ cmd = "cp"
80
+ cmd += "_r" if options.delete :r
81
+ options[:preserve] = true if options.delete :p
82
+ dest = argv.pop
83
+ argv = argv[0] if argv.size == 1
84
+ FileUtils.send cmd, argv, dest, options
85
+ end
86
+ end
87
+
88
+ ##
89
+ # Create a link to the specified TARGET with LINK_NAME.
90
+ #
91
+ # ruby -run -e ln -- [OPTION] TARGET LINK_NAME
92
+ #
93
+ # -s make symbolic links instead of hard links
94
+ # -f remove existing destination files
95
+ # -v verbose
96
+ #
97
+
98
+ def ln
99
+ setup("sf") do |argv, options|
100
+ cmd = "ln"
101
+ cmd += "_s" if options.delete :s
102
+ options[:force] = true if options.delete :f
103
+ dest = argv.pop
104
+ argv = argv[0] if argv.size == 1
105
+ FileUtils.send cmd, argv, dest, options
106
+ end
107
+ end
108
+
109
+ ##
110
+ # Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
111
+ #
112
+ # ruby -run -e mv -- [OPTION] SOURCE DEST
113
+ #
114
+ # -v verbose
115
+ #
116
+
117
+ def mv
118
+ setup do |argv, options|
119
+ dest = argv.pop
120
+ argv = argv[0] if argv.size == 1
121
+ FileUtils.mv argv, dest, options
122
+ end
123
+ end
124
+
125
+ ##
126
+ # Remove the FILE
127
+ #
128
+ # ruby -run -e rm -- [OPTION] FILE
129
+ #
130
+ # -f ignore nonexistent files
131
+ # -r remove the contents of directories recursively
132
+ # -v verbose
133
+ #
134
+
135
+ def rm
136
+ setup("fr") do |argv, options|
137
+ cmd = "rm"
138
+ cmd += "_r" if options.delete :r
139
+ options[:force] = true if options.delete :f
140
+ FileUtils.send cmd, argv, options
141
+ end
142
+ end
143
+
144
+ ##
145
+ # Create the DIR, if they do not already exist.
146
+ #
147
+ # ruby -run -e mkdir -- [OPTION] DIR
148
+ #
149
+ # -p no error if existing, make parent directories as needed
150
+ # -v verbose
151
+ #
152
+
153
+ def mkdir
154
+ setup("p") do |argv, options|
155
+ cmd = "mkdir"
156
+ cmd += "_p" if options.delete :p
157
+ FileUtils.send cmd, argv, options
158
+ end
159
+ end
160
+
161
+ ##
162
+ # Remove the DIR.
163
+ #
164
+ # ruby -run -e rmdir -- [OPTION] DIR
165
+ #
166
+ # -p remove DIRECTORY and its ancestors.
167
+ # -v verbose
168
+ #
169
+
170
+ def rmdir
171
+ setup("p") do |argv, options|
172
+ options[:parents] = true if options.delete :p
173
+ FileUtils.rmdir argv, options
174
+ end
175
+ end
176
+
177
+ ##
178
+ # Copy SOURCE to DEST.
179
+ #
180
+ # ruby -run -e install -- [OPTION] SOURCE DEST
181
+ #
182
+ # -p apply access/modification times of SOURCE files to
183
+ # corresponding destination files
184
+ # -m set permission mode (as in chmod), instead of 0755
185
+ # -v verbose
186
+ #
187
+
188
+ def install
189
+ setup("pm:") do |argv, options|
190
+ options[:mode] = (mode = options.delete :m) ? mode.oct : 0755
191
+ options[:preserve] = true if options.delete :p
192
+ dest = argv.pop
193
+ argv = argv[0] if argv.size == 1
194
+ FileUtils.install argv, dest, options
195
+ end
196
+ end
197
+
198
+ ##
199
+ # Change the mode of each FILE to OCTAL-MODE.
200
+ #
201
+ # ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
202
+ #
203
+ # -v verbose
204
+ #
205
+
206
+ def chmod
207
+ setup do |argv, options|
208
+ mode = argv.shift.oct
209
+ FileUtils.chmod mode, argv, options
210
+ end
211
+ end
212
+
213
+ ##
214
+ # Update the access and modification times of each FILE to the current time.
215
+ #
216
+ # ruby -run -e touch -- [OPTION] FILE
217
+ #
218
+ # -v verbose
219
+ #
220
+
221
+ def touch
222
+ setup do |argv, options|
223
+ FileUtils.touch argv, options
224
+ end
225
+ end
226
+
227
+ ##
228
+ # Wait until the file becomes writable.
229
+ #
230
+ # ruby -run -e wait_writable -- [OPTION] FILE
231
+ #
232
+ # -n RETRY count to retry
233
+ # -w SEC each wait time in seconds
234
+ # -v verbose
235
+ #
236
+
237
+ def wait_writable
238
+ setup("n:w:v") do |argv, options|
239
+ verbose = options[:verbose]
240
+ n = options[:n] and n = Integer(n)
241
+ wait = (wait = options[:w]) ? Float(wait) : 0.2
242
+ argv.each do |file|
243
+ begin
244
+ open(file, "r+b")
245
+ rescue Errno::ENOENT
246
+ break
247
+ rescue Errno::EACCES => e
248
+ raise if n and (n -= 1) <= 0
249
+ puts e
250
+ STDOUT.flush
251
+ sleep wait
252
+ retry
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ ##
259
+ # Create makefile using mkmf.
260
+ #
261
+ # ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
262
+ #
263
+ # -d ARGS run dir_config
264
+ # -h ARGS run have_header
265
+ # -l ARGS run have_library
266
+ # -f ARGS run have_func
267
+ # -v ARGS run have_var
268
+ # -t ARGS run have_type
269
+ # -m ARGS run have_macro
270
+ # -c ARGS run have_const
271
+ # --vendor install to vendor_ruby
272
+ #
273
+
274
+ def mkmf
275
+ setup("d:h:l:f:v:t:m:c:", "vendor") do |argv, options|
276
+ require 'mkmf'
277
+ opt = options[:d] and opt.split(/:/).each {|n| dir_config(*n.split(/,/))}
278
+ opt = options[:h] and opt.split(/:/).each {|n| have_header(*n.split(/,/))}
279
+ opt = options[:l] and opt.split(/:/).each {|n| have_library(*n.split(/,/))}
280
+ opt = options[:f] and opt.split(/:/).each {|n| have_func(*n.split(/,/))}
281
+ opt = options[:v] and opt.split(/:/).each {|n| have_var(*n.split(/,/))}
282
+ opt = options[:t] and opt.split(/:/).each {|n| have_type(*n.split(/,/))}
283
+ opt = options[:m] and opt.split(/:/).each {|n| have_macro(*n.split(/,/))}
284
+ opt = options[:c] and opt.split(/:/).each {|n| have_const(*n.split(/,/))}
285
+ $configure_args["--vendor"] = true if options[:vendor]
286
+ create_makefile(*argv)
287
+ end
288
+ end
289
+
290
+ ##
291
+ # Run WEBrick HTTP server.
292
+ #
293
+ # ruby -run -e httpd -- [OPTION] DocumentRoot
294
+ #
295
+ # --bind-address=ADDR address to bind
296
+ # --port=NUM listening port number
297
+ # --max-clients=MAX max number of simultaneous clients
298
+ # --temp-dir=DIR temporary directory
299
+ # --do-not-reverse-lookup disable reverse lookup
300
+ # --request-timeout=SECOND request timeout in seconds
301
+ # --http-version=VERSION HTTP version
302
+ # -v verbose
303
+ #
304
+
305
+ def httpd
306
+ setup("", "BindAddress=ADDR", "Port=PORT", "MaxClients=NUM", "TempDir=DIR",
307
+ "DoNotReverseLookup", "RequestTimeout=SECOND", "HTTPVersion=VERSION") do
308
+ |argv, options|
309
+ require 'webrick'
310
+ opt = options[:RequestTimeout] and options[:RequestTimeout] = opt.to_i
311
+ [:Port, :MaxClients].each do |name|
312
+ opt = options[name] and (options[name] = Integer(opt)) rescue nil
313
+ end
314
+ unless argv.empty?
315
+ options[:DocumentRoot] = argv.shift
316
+ end
317
+ s = WEBrick::HTTPServer.new(options)
318
+ shut = proc {s.shutdown}
319
+ Signal.trap("TERM", shut)
320
+ Signal.trap("QUIT", shut) if Signal.list.has_key?("QUIT")
321
+ if STDIN.tty?
322
+ Signal.trap("HUP", shut) if Signal.list.has_key?("HUP")
323
+ Signal.trap("INT", shut)
324
+ end
325
+ s.start
326
+ end
327
+ end
328
+
329
+ ##
330
+ # Display help message.
331
+ #
332
+ # ruby -run -e help [COMMAND]
333
+ #
334
+
335
+ def help
336
+ setup do |argv,|
337
+ all = argv.empty?
338
+ open(__FILE__) do |me|
339
+ while me.gets("##\n")
340
+ if help = me.gets("\n\n")
341
+ if all or argv.delete help[/-e \w+/].sub(/-e /, "")
342
+ print help.gsub(/^# ?/, "")
343
+ end
344
+ end
345
+ end
346
+ end
347
+ end
348
+ end