glark 1.9.0 → 1.10.0
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/bin/glark +2 -2
- data/lib/glark.rb +1 -1
- data/lib/glark/app/app.rb +48 -0
- data/lib/glark/app/help.rb +103 -0
- data/lib/glark/app/info/options.rb +84 -0
- data/lib/glark/app/options.rb +201 -0
- data/lib/glark/app/rcfile.rb +49 -0
- data/lib/glark/app/runner.rb +140 -0
- data/lib/glark/app/spec.rb +19 -0
- data/lib/glark/input/filter/criteria_opts.rb +41 -0
- data/lib/glark/input/filter/dir_criteria_opts.rb +37 -0
- data/lib/glark/input/filter/file_criteria_opts.rb +33 -0
- data/lib/glark/input/filter/filter.rb +59 -0
- data/lib/glark/input/filter/options.rb +171 -0
- data/lib/glark/input/options.rb +120 -0
- data/lib/glark/input/range.rb +104 -0
- data/lib/glark/input/spec.rb +39 -0
- data/lib/glark/io/file/archive_file.rb +64 -0
- data/lib/glark/io/file/binary_file.rb +19 -0
- data/lib/glark/io/file/file.rb +57 -0
- data/lib/glark/io/file/gz_file.rb +21 -0
- data/lib/glark/io/file/tar_file.rb +35 -0
- data/lib/glark/io/file/tar_gz_file.rb +52 -0
- data/lib/glark/io/file/zip_file.rb +39 -0
- data/lib/glark/match/and.rb +83 -0
- data/lib/glark/match/and_distance.rb +58 -0
- data/lib/glark/match/compound.rb +34 -0
- data/lib/glark/match/expression.rb +63 -0
- data/lib/glark/match/factory.rb +173 -0
- data/lib/glark/match/ior.rb +20 -0
- data/lib/glark/match/options.rb +74 -0
- data/lib/glark/match/or.rb +41 -0
- data/lib/glark/match/re.rb +81 -0
- data/lib/glark/match/re_factory.rb +44 -0
- data/lib/glark/match/spec.rb +59 -0
- data/lib/glark/match/xor.rb +20 -0
- data/lib/glark/output/binary_file_summary.rb +17 -0
- data/lib/glark/output/common.rb +43 -0
- data/lib/glark/output/context.rb +57 -0
- data/lib/glark/output/count.rb +26 -0
- data/lib/glark/output/file_header.rb +20 -0
- data/lib/glark/output/file_name_only.rb +35 -0
- data/lib/glark/output/formatted.rb +22 -0
- data/lib/glark/output/glark_count.rb +23 -0
- data/lib/glark/output/glark_format.rb +62 -0
- data/lib/glark/output/glark_lines.rb +36 -0
- data/lib/glark/output/grep_count.rb +18 -0
- data/lib/glark/output/grep_lines.rb +42 -0
- data/lib/glark/output/line_status.rb +46 -0
- data/lib/glark/output/lines.rb +100 -0
- data/lib/glark/output/match_list.rb +15 -0
- data/lib/glark/output/options.rb +103 -0
- data/lib/glark/output/results.rb +23 -0
- data/lib/glark/output/spec.rb +105 -0
- data/lib/glark/output/unfiltered_lines.rb +28 -0
- data/lib/glark/util/colors/options.rb +143 -0
- data/lib/glark/util/colors/spec.rb +21 -0
- data/lib/glark/util/highlight.rb +108 -0
- data/lib/glark/util/io/depth.rb +29 -0
- data/lib/glark/util/io/fileset.rb +162 -0
- data/lib/glark/util/io/filter/criteria.rb +49 -0
- data/lib/glark/util/io/filter/filter.rb +10 -0
- data/lib/glark/util/io/lines.rb +117 -0
- data/lib/glark/util/option.rb +34 -0
- data/lib/glark/util/options.rb +12 -0
- data/lib/glark/util/optutil.rb +69 -0
- data/lib/glark/util/timestamper.rb +18 -0
- data/man/glark.1 +1134 -0
- data/test/glark/app/and_test.rb +82 -0
- data/test/glark/app/compound_test.rb +33 -0
- data/test/glark/app/context_test.rb +43 -0
- data/test/glark/app/count_test.rb +89 -0
- data/test/glark/app/dump_test.rb +16 -0
- data/test/glark/app/expression_file_test.rb +22 -0
- data/test/glark/app/extended_regexp_test.rb +17 -0
- data/test/glark/app/extract_matches_test.rb +27 -0
- data/test/glark/app/files_with_match_test.rb +32 -0
- data/test/glark/app/files_without_match_test.rb +26 -0
- data/test/glark/app/filter_test.rb +118 -0
- data/test/glark/app/highlight_test.rb +78 -0
- data/test/glark/app/ignore_case_test.rb +22 -0
- data/test/glark/app/invert_test.rb +49 -0
- data/test/glark/app/ior_test.rb +21 -0
- data/test/glark/app/label_test.rb +28 -0
- data/test/glark/app/line_number_color_test.rb +42 -0
- data/test/glark/app/line_numbers_test.rb +42 -0
- data/test/glark/app/match_limit_test.rb +49 -0
- data/test/glark/app/options_test.rb +722 -0
- data/test/glark/app/range_test.rb +101 -0
- data/test/glark/app/rcfile_test.rb +113 -0
- data/test/glark/app/record_separator_test.rb +32 -0
- data/test/glark/app/regexp_test.rb +48 -0
- data/test/glark/app/tc.rb +92 -0
- data/test/glark/app/text_color_test.rb +31 -0
- data/test/glark/app/whole_lines_test.rb +17 -0
- data/test/glark/app/whole_words_test.rb +42 -0
- data/test/glark/app/xor_test.rb +19 -0
- data/test/glark/input/binary_file_test.rb +0 -0
- data/test/glark/input/directory_test.rb +202 -0
- data/test/glark/input/dirname_test.rb +69 -0
- data/test/glark/input/exclude_matching_test.rb +20 -0
- data/test/glark/input/ext_test.rb +65 -0
- data/test/glark/input/filter/criteria_test.rb +91 -0
- data/test/glark/input/filter/filter_spec_test.rb +27 -0
- data/test/glark/input/filter/filter_test.rb +21 -0
- data/test/glark/input/name_test.rb +75 -0
- data/test/glark/input/path_test.rb +72 -0
- data/test/glark/input/range_test.rb +82 -0
- data/test/glark/input/size_limit_test.rb +51 -0
- data/test/glark/input/split_as_path_test.rb +28 -0
- data/test/glark/match_test.rb +192 -0
- data/test/glark/resources.rb +21 -0
- data/test/glark/tc.rb +37 -0
- data/test/resources/add.rb +10 -0
- data/test/resources/echo.rb +2 -0
- data/test/resources/greet.rb +13 -0
- metadata +198 -28
- data/README +0 -0
- data/bin/jlark +0 -63
- data/lib/glark/expression.rb +0 -440
- data/lib/glark/exprfactory.rb +0 -248
- data/lib/glark/glark.rb +0 -297
- data/lib/glark/help.rb +0 -85
- data/lib/glark/input.rb +0 -183
- data/lib/glark/options.rb +0 -757
- data/lib/glark/output.rb +0 -266
- data/test/lib/glark/glark_test.rb +0 -317
- data/test/lib/glark/options_test.rb +0 -891
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
require 'glark/match/or'
|
6
|
+
|
7
|
+
# Evaluates the expressions, and is satisfied when any one returns true.
|
8
|
+
class InclusiveOrExpression < OrExpression
|
9
|
+
def is_match? matched_ops
|
10
|
+
return matched_ops.size > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def operator
|
14
|
+
"or"
|
15
|
+
end
|
16
|
+
|
17
|
+
def criteria
|
18
|
+
ops.size == 2 ? "either" : "any of"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
# Options for matching.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'riel/log'
|
9
|
+
require 'glark/match/spec'
|
10
|
+
require 'glark/util/options'
|
11
|
+
|
12
|
+
module Glark
|
13
|
+
class MatchOptions < MatchSpec
|
14
|
+
include OptionUtil
|
15
|
+
|
16
|
+
def initialize colors, optdata
|
17
|
+
super colors
|
18
|
+
add_as_options optdata
|
19
|
+
end
|
20
|
+
|
21
|
+
def config_fields
|
22
|
+
fields = {
|
23
|
+
"ignore-case" => @ignorecase,
|
24
|
+
"text-color" => text_colors.join(' '),
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def dump_fields
|
29
|
+
fields = {
|
30
|
+
"expr" => @expr,
|
31
|
+
"extract_matches" => @extract_matches,
|
32
|
+
"ignorecase" => @ignorecase,
|
33
|
+
"text_colors" => text_colors.compact.collect { |hl| colorize(hl, "text") }.join(", "),
|
34
|
+
"whole_lines" => @whole_lines,
|
35
|
+
"whole_words" => @whole_words,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_fields fields
|
40
|
+
fields.each do |name, values|
|
41
|
+
case name
|
42
|
+
when "ignore-case"
|
43
|
+
@ignorecase = to_boolean values.last
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_as_options optdata
|
49
|
+
add_opt_true optdata, :whole_words, %w{ -w --word }
|
50
|
+
add_opt_true optdata, :ignorecase, %w{ -i --ignore-case }
|
51
|
+
add_opt_true optdata, :whole_lines, %w{ -x --line-regexp }
|
52
|
+
add_opt_true optdata, :extended, %w{ --extended }
|
53
|
+
|
54
|
+
optdata << expr_file_option = {
|
55
|
+
:tags => %w{ -f --file },
|
56
|
+
:arg => [ :string ],
|
57
|
+
:set => Proc.new { |fname| @expr = create_expression_factory.read_file fname }
|
58
|
+
}
|
59
|
+
|
60
|
+
add_opt_blk(optdata, %w{ -o -a }) do |md, opt, args|
|
61
|
+
args.unshift opt
|
62
|
+
@expr = create_expression_factory.make_expression args
|
63
|
+
end
|
64
|
+
|
65
|
+
optdata << text_color_option = {
|
66
|
+
:tags => %w{ --text-color },
|
67
|
+
:arg => [ :string ],
|
68
|
+
:set => Proc.new { |val| @colors.text_colors = [ @colors.create_color("text-color", val) ] }
|
69
|
+
}
|
70
|
+
|
71
|
+
add_opt_true optdata, :extract_matches, %w{ -y --extract-matches }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
require 'glark/match/compound'
|
6
|
+
|
7
|
+
# A collection of expressions, evaluated as 'or'.
|
8
|
+
class OrExpression < CompoundExpression
|
9
|
+
|
10
|
+
def evaluate line, lnum, file, formatter
|
11
|
+
matched_ops = @ops.select do |op|
|
12
|
+
op.evaluate line, lnum, file, formatter
|
13
|
+
end
|
14
|
+
|
15
|
+
if is_match? matched_ops
|
16
|
+
lastmatch = matched_ops[-1]
|
17
|
+
@last_start = lastmatch.start_position
|
18
|
+
@last_end = lastmatch.end_position
|
19
|
+
@match_line_number = lnum
|
20
|
+
|
21
|
+
add_match lnum
|
22
|
+
true
|
23
|
+
else
|
24
|
+
false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"(" + @ops.collect { |op| op.to_s }.join(" " + operator + " ") + ")"
|
30
|
+
end
|
31
|
+
|
32
|
+
def end_position
|
33
|
+
@last_end
|
34
|
+
end
|
35
|
+
|
36
|
+
def explain level = 0
|
37
|
+
str = " " * level + criteria + ":\n"
|
38
|
+
str += @ops.collect { |op| op.explain(level + 4) }.join(" " * level + operator + "\n")
|
39
|
+
str
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
require 'glark/match/expression'
|
6
|
+
require 'glark/util/highlight'
|
7
|
+
|
8
|
+
# Applies a regular expression against a File.
|
9
|
+
class RegexpExpression < Expression
|
10
|
+
include Highlight
|
11
|
+
|
12
|
+
attr_reader :re
|
13
|
+
|
14
|
+
def initialize re, hlidx, text_colors = nil, extract_matches = false
|
15
|
+
@re = re
|
16
|
+
|
17
|
+
if @text_colors = text_colors
|
18
|
+
@hlidx = if @text_colors.length > 0
|
19
|
+
hlidx % @text_colors.length
|
20
|
+
else
|
21
|
+
0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@extract_matches = extract_matches
|
25
|
+
|
26
|
+
super()
|
27
|
+
end
|
28
|
+
|
29
|
+
def == other
|
30
|
+
@re == other.re
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
@re.inspect
|
35
|
+
end
|
36
|
+
|
37
|
+
def match? line
|
38
|
+
@re.match line
|
39
|
+
end
|
40
|
+
|
41
|
+
def evaluate line, lnum, file, formatter
|
42
|
+
md = match? line
|
43
|
+
return false unless md
|
44
|
+
|
45
|
+
if @extract_matches
|
46
|
+
if md.kind_of? MatchData
|
47
|
+
line.replace md[-1] + "\n"
|
48
|
+
else
|
49
|
+
warn "--not is incompatible with -v"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
@match_line_number = lnum
|
54
|
+
|
55
|
+
if @text_colors && @text_colors.size > 0
|
56
|
+
highlight_match lnum, file, formatter
|
57
|
+
end
|
58
|
+
|
59
|
+
add_match lnum
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def explain level = 0
|
64
|
+
" " * level + to_s + "\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
def highlight_match lnum, file, formatter
|
68
|
+
lnums = file.get_region lnum
|
69
|
+
return unless lnums
|
70
|
+
|
71
|
+
lnums.each do |ln|
|
72
|
+
str = formatter.formatted[ln] || file.get_line(ln)
|
73
|
+
formatter.formatted[ln] = str.gsub(@re) do |m|
|
74
|
+
lastcapts = Regexp.last_match.captures
|
75
|
+
# the index of the first non-nil capture:
|
76
|
+
miidx = (0 ... lastcapts.length).find { |mi| lastcapts[mi] } || @hlidx
|
77
|
+
adorn(@text_colors[miidx], m)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
# RegexpExpression factory.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'riel/regexp'
|
9
|
+
require 'glark/match/re'
|
10
|
+
|
11
|
+
class RegexpExpressionFactory
|
12
|
+
include Loggable
|
13
|
+
|
14
|
+
attr_reader :count
|
15
|
+
|
16
|
+
def initialize exprspec
|
17
|
+
@count = 0
|
18
|
+
@extended = exprspec[:extended]
|
19
|
+
@extract_matches = exprspec[:extract_matches]
|
20
|
+
@ignorecase = exprspec[:ignorecase]
|
21
|
+
@text_colors = exprspec[:text_colors]
|
22
|
+
@wholelines = exprspec[:whole_lines]
|
23
|
+
@wholewords = exprspec[:whole_words]
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_expression pattern, negated = false
|
27
|
+
# this check is because they may have omitted the pattern, e.g.:
|
28
|
+
# % glark *.cpp
|
29
|
+
if File.exists? pattern
|
30
|
+
warn "pattern '#{pattern}' exists as a file.\n Pattern may have been omitted."
|
31
|
+
end
|
32
|
+
|
33
|
+
regex = Regexp.create(pattern.dup,
|
34
|
+
:negated => negated,
|
35
|
+
:ignorecase => @ignorecase,
|
36
|
+
:wholewords => @wholewords,
|
37
|
+
:wholelines => @wholelines,
|
38
|
+
:extended => @extended)
|
39
|
+
|
40
|
+
re = RegexpExpression.new regex, @count, @text_colors, @extract_matches
|
41
|
+
@count += 1
|
42
|
+
re
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
# Options for matching.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'riel/log'
|
9
|
+
require 'glark/match/factory'
|
10
|
+
require 'glark/util/colors/spec'
|
11
|
+
|
12
|
+
module Glark
|
13
|
+
class MatchSpec
|
14
|
+
attr_accessor :expr # the expression to be evaluated
|
15
|
+
attr_accessor :extended # whether to use extended regular expressions
|
16
|
+
attr_accessor :extract_matches
|
17
|
+
attr_accessor :ignorecase # match case
|
18
|
+
attr_accessor :whole_lines # true means patterns must match the entire line
|
19
|
+
attr_accessor :whole_words # true means all patterns are '\b'ed front and back
|
20
|
+
|
21
|
+
def initialize colors
|
22
|
+
@colors = colors
|
23
|
+
@expr = nil
|
24
|
+
@extended = false
|
25
|
+
@extract_matches = false
|
26
|
+
@ignorecase = false
|
27
|
+
@whole_lines = false
|
28
|
+
@whole_words = false
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_expression_factory
|
32
|
+
exprargs = Hash.new
|
33
|
+
exprargs[:extended] = @extended
|
34
|
+
exprargs[:extract_matches] = @extract_matches
|
35
|
+
exprargs[:ignorecase] = @ignorecase
|
36
|
+
exprargs[:text_colors] = text_colors
|
37
|
+
exprargs[:whole_lines] = @whole_lines
|
38
|
+
exprargs[:whole_words] = @whole_words
|
39
|
+
|
40
|
+
ExpressionFactory.new exprargs
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_expression args, warn_option = false
|
44
|
+
@expr = create_expression_factory.make_expression args, warn_option
|
45
|
+
end
|
46
|
+
|
47
|
+
def text_colors
|
48
|
+
@colors.text_colors
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_text_colors text_colors
|
52
|
+
@colors.text_colors = text_colors
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_text_color index, text_color
|
56
|
+
@colors.text_colors[index] = text_color
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
require 'glark/match/or'
|
6
|
+
|
7
|
+
# Evaluates the expressions, and is satisfied if only one returns true.
|
8
|
+
class ExclusiveOrExpression < OrExpression
|
9
|
+
def is_match? matched_ops
|
10
|
+
return matched_ops.size == 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def operator
|
14
|
+
"xor"
|
15
|
+
end
|
16
|
+
|
17
|
+
def criteria
|
18
|
+
"only one of"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
require 'glark/output/common'
|
6
|
+
|
7
|
+
class BinaryFileSummary < Common
|
8
|
+
def display_matches?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
def process_end lnum
|
13
|
+
if matched?
|
14
|
+
@out.puts "Binary file " + @file.fname.to_s + " matches"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#!ruby -w
|
3
|
+
# vim: set filetype=ruby : set sw=2
|
4
|
+
|
5
|
+
# Generic output.
|
6
|
+
|
7
|
+
require 'glark/io/file/file'
|
8
|
+
require 'glark/output/formatted'
|
9
|
+
|
10
|
+
class Common < Formatted
|
11
|
+
def initialize file, spec
|
12
|
+
super()
|
13
|
+
|
14
|
+
@file = file
|
15
|
+
@invert_match = spec.invert_match
|
16
|
+
@label = spec.label
|
17
|
+
@match_limit = spec.match_limit
|
18
|
+
@out = spec.out
|
19
|
+
@show_file_name = spec.show_file_names
|
20
|
+
@show_line_numbers = spec.show_line_numbers
|
21
|
+
end
|
22
|
+
|
23
|
+
def display_matches?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def at_match_limit?
|
28
|
+
@match_limit && @count >= @match_limit
|
29
|
+
end
|
30
|
+
|
31
|
+
def displayed_name
|
32
|
+
@label || @file.fname
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_match startline, endline
|
36
|
+
super()
|
37
|
+
end
|
38
|
+
|
39
|
+
def process_match startline, endline, fromline, toline
|
40
|
+
add_match startline, endline
|
41
|
+
return at_match_limit?
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
module Glark
|
5
|
+
class Context
|
6
|
+
attr_accessor :after
|
7
|
+
attr_accessor :before
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@after = 0
|
11
|
+
@before = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear
|
15
|
+
@after = 0
|
16
|
+
@before = 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_fields fields
|
20
|
+
fields.each do |name, values|
|
21
|
+
case name
|
22
|
+
when 'context'
|
23
|
+
@after = @before = values.last.to_i
|
24
|
+
when 'after', 'after-context'
|
25
|
+
@after = values.last.to_i
|
26
|
+
when 'before', 'before-context'
|
27
|
+
@before = values.last.to_i
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_as_option optdata
|
33
|
+
optdata << context_option = {
|
34
|
+
:tags => %w{ -C --context },
|
35
|
+
:res => %r{ ^ - ([1-9]\d*) $ }x,
|
36
|
+
:arg => [ :optional, :integer ],
|
37
|
+
:set => Proc.new { |val, opt, args| @after = @before = val || 2 },
|
38
|
+
:rc => %w{ context },
|
39
|
+
}
|
40
|
+
|
41
|
+
optdata << context_after_option = {
|
42
|
+
:tags => %w{ --after-context -A },
|
43
|
+
:arg => [ :integer ],
|
44
|
+
:set => Proc.new { |val| @after = val },
|
45
|
+
:rc => %w{ after-context },
|
46
|
+
}
|
47
|
+
|
48
|
+
optdata << context_before_option = {
|
49
|
+
:tags => %w{ --before-context -B },
|
50
|
+
:arg => [ :integer ],
|
51
|
+
:set => Proc.new { |val| @before = val },
|
52
|
+
:rc => %w{ before-context },
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|