glark 1.10.2 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/glark/app/app.rb CHANGED
@@ -13,7 +13,7 @@ module Glark
13
13
  class App
14
14
  def initialize
15
15
  begin
16
- Log.set_widths(-15, -40, -40)
16
+ Logue::Log.set_widths(-15, -40, -40)
17
17
 
18
18
  opts = AppOptions.new
19
19
  opts.run ARGV
@@ -32,7 +32,7 @@ module Glark
32
32
  rescue => e
33
33
  # show the message, and the stack trace only if verbose:
34
34
  $stderr.puts "error: #{e}"
35
- if Log.verbose
35
+ if Logue::Log.verbose
36
36
  $stderr.puts e.backtrace
37
37
  raise
38
38
  else
@@ -7,7 +7,7 @@ require 'glark/util/options'
7
7
 
8
8
  module Glark
9
9
  PACKAGE = 'glark'
10
- VERSION = '1.10.2'
10
+ VERSION = '1.10.3'
11
11
 
12
12
  class InfoOptions < Options
13
13
  attr_reader :colors
@@ -24,8 +24,8 @@ module Glark
24
24
  {
25
25
  "known-nontext-files" => FileType.nontext_extensions.sort.join(' '),
26
26
  "known-text-files" => FileType.text_extensions.sort.join(' '),
27
- "quiet" => Log.quiet,
28
- "verbose" => Log.verbose,
27
+ "quiet" => Logue::Log.quiet,
28
+ "verbose" => Logue::Log.verbose,
29
29
  }
30
30
  end
31
31
 
@@ -34,9 +34,9 @@ module Glark
34
34
  "explain" => @explain,
35
35
  "known_nontext_files" => FileType.nontext_extensions.join(", "),
36
36
  "known_text_files" => FileType.text_extensions.join(", "),
37
- "quiet" => Log.quiet,
37
+ "quiet" => Logue::Log.quiet,
38
38
  "ruby version" => RUBY_VERSION,
39
- "verbose" => Log.verbose,
39
+ "verbose" => Logue::Log.verbose,
40
40
  "version" => Glark::VERSION,
41
41
  }
42
42
  end
@@ -53,25 +53,25 @@ module Glark
53
53
  FileType.set_text ext
54
54
  end
55
55
  when "quiet"
56
- Log.quiet = to_boolean(values.last)
56
+ Logue::Log.quiet = to_boolean(values.last)
57
57
  when "verbose"
58
- Log.verbose = to_boolean(values.last) ? 1 : nil
58
+ Logue::Log.verbose = to_boolean(values.last) ? 1 : nil
59
59
  when "verbosity"
60
- Log.verbose = values.last.to_i
60
+ Logue::Log.verbose = values.last.to_i
61
61
  end
62
62
  end
63
63
  end
64
64
 
65
65
  def add_as_options optdata
66
66
  add_opt_blk(optdata, %w{ -V --version }) { show_version }
67
- add_opt_blk(optdata, %w{ --verbose }) { Log.verbose = true }
67
+ add_opt_blk(optdata, %w{ --verbose }) { Logue::Log.verbose = true }
68
68
  add_opt_blk(optdata, %w{ -? --help }) { Help.new.show_usage; exit 0 }
69
69
  add_opt_blk(optdata, %w{ --man }) { Help.new.show_man; exit 0 }
70
70
 
71
71
  add_opt_true optdata, :explain, %w{ --explain }
72
72
 
73
- add_opt_blk(optdata, %w{ -q -s --quiet --messages }) { Log.quiet = true }
74
- add_opt_blk(optdata, %w{ -Q -S --no-quiet --no-messages }) { Log.quiet = false }
73
+ add_opt_blk(optdata, %w{ -q -s --quiet --messages }) { Logue::Log.quiet = true }
74
+ add_opt_blk(optdata, %w{ -Q -S --no-quiet --no-messages }) { Logue::Log.quiet = false }
75
75
  end
76
76
 
77
77
  def show_version
@@ -3,7 +3,8 @@
3
3
 
4
4
  require 'rubygems'
5
5
  require 'riel/dir'
6
- require 'riel/optproc'
6
+ require 'ragol/optproc/optproc'
7
+ require 'riel/env'
7
8
  require 'glark/app/info/options'
8
9
  require 'glark/app/rcfile'
9
10
  require 'glark/app/spec'
@@ -13,8 +14,21 @@ require 'glark/output/options'
13
14
  require 'glark/util/colors/options'
14
15
  require 'glark/util/options'
15
16
  require 'glark/util/optutil'
17
+ require 'pathname'
16
18
 
17
19
  module Glark
20
+ class OptionSet < OptProc::OptionSet
21
+ include Logue::Loggable
22
+
23
+ def set_option results
24
+ # intercept these, which we'll use to create the expression:
25
+ %w{ -o --or --and -a \( \) --xor }.each do |tag|
26
+ return nil if results.current_arg.index(tag) == 0
27
+ end
28
+ super
29
+ end
30
+ end
31
+
18
32
  class AppOptions < AppSpec
19
33
  include OptionUtil
20
34
 
@@ -39,7 +53,7 @@ module Glark
39
53
 
40
54
  super @input_options, @match_options, @output_options
41
55
 
42
- @optset = OptProc::OptionSet.new optdata
56
+ @optset = OptionSet.new optdata
43
57
  end
44
58
 
45
59
  def run args
@@ -161,8 +175,8 @@ module Glark
161
175
  @info_options.show_version if @args.size == 1 && @args.first == "-v"
162
176
 
163
177
  @match_options.expr = nil
164
-
165
- nil while @args.size > 0 && @optset.process_option(@args)
178
+
179
+ @optset.process(@args)
166
180
 
167
181
  unless @match_options.expr
168
182
  read_expression
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
+ require 'pathname'
5
+
4
6
  module Glark
5
7
  class RCFile
6
8
  COMMENT_RE = Regexp.new '\s*#.*'
@@ -3,7 +3,7 @@
3
3
  # vim: set filetype=ruby : set sw=2
4
4
 
5
5
  require 'rubygems'
6
- require 'riel/log/loggable'
6
+ require 'logue/loggable'
7
7
  require 'glark/app/options'
8
8
  require 'glark/io/file/binary_file'
9
9
  require 'glark/io/file/gz_file'
@@ -17,7 +17,7 @@ $stderr.sync = true # unbuffer
17
17
  module Glark
18
18
  # The main processor.
19
19
  class Runner
20
- include Loggable
20
+ include Logue::Loggable
21
21
 
22
22
  GZ_RE = Regexp.new '\.gz$'
23
23
  TAR_GZ_RE = Regexp.new '\.(?:tgz|tar\.gz)$'
@@ -2,11 +2,13 @@
2
2
  #!ruby -w
3
3
  # vim: set filetype=ruby : set sw=2
4
4
 
5
+ require 'rubygems'
6
+ require 'logue/loggable'
5
7
  require 'glark/util/io/filter/filter'
6
8
 
7
9
  module Glark
8
10
  class PatternFilter < Filter
9
- include Loggable
11
+ include Logue::Loggable
10
12
 
11
13
  attr_reader :pattern
12
14
 
@@ -5,13 +5,14 @@
5
5
  # Options for input.
6
6
 
7
7
  require 'rubygems'
8
+ require 'logue/loggable'
8
9
  require 'glark/input/spec'
9
10
  require 'glark/util/io/fileset'
10
11
  require 'glark/util/options'
11
12
 
12
13
  module Glark
13
14
  class InputOptions < InputSpec
14
- include OptionUtil, Loggable
15
+ include OptionUtil, Logue::Loggable
15
16
 
16
17
  def initialize optdata
17
18
  super()
@@ -104,7 +105,7 @@ module Glark
104
105
  optdata << {
105
106
  :tags => %w{ --binary-files },
106
107
  :arg => [ :required, :regexp, re ],
107
- :set => Proc.new { |md| @binary_files = md[1] },
108
+ :set => Proc.new { |md| @binary_files = md },
108
109
  :rc => %w{ binary-files },
109
110
  }
110
111
 
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
+ require 'logue/loggable'
5
+
4
6
  module Glark
5
7
  class RangeError < RuntimeError
6
8
  end
7
9
 
8
10
  class Range
9
- include Loggable, Comparable
11
+ include Logue::Loggable, Comparable
10
12
 
11
13
  PCT_RE = Regexp.new '([\.\d]+)%'
12
14
 
@@ -77,27 +79,19 @@ module Glark
77
79
  optdata << {
78
80
  :tags => %w{ --after },
79
81
  :arg => [ :required, :regexp, %r{ (\d+%?) $ }x ],
80
- :set => Proc.new { |md| @from = md[1] }
82
+ :set => Proc.new { |md| @from = md }
81
83
  }
82
84
 
83
85
  optdata << {
84
86
  :tags => %w{ --before },
85
87
  :arg => [ :required, :regexp, %r{ (\d+%?) $ }x ],
86
- :set => Proc.new { |md| @to = md[1] }
88
+ :set => Proc.new { |md| @to = md }
87
89
  }
88
90
 
89
91
  optdata << {
90
92
  :tags => %w{ -R --range },
91
- :arg => [ :required, :regexp, Regexp.new('(\d+%?),(\d+%?)') ],
92
- :set => Proc.new do |md, opt, args|
93
- if md && md[1] && md[2]
94
- @from = md[1]
95
- @to = md[2]
96
- else
97
- @from = args.shift
98
- @to = args.shift
99
- end
100
- end
93
+ :arg => [ :required, :regexp, Regexp.new('(\d+%?,\d+%?)') ],
94
+ :set => Proc.new { |md, opt, args| @from, @to = md.split(',') }
101
95
  }
102
96
  end
103
97
  end
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
+ require 'rubygems'
5
+ require 'logue/loggable'
4
6
  require 'glark/io/file/gz_file'
5
7
  require 'glark/io/file/tar_file'
6
8
 
7
9
  module Glark
8
10
  class TarGzFile
9
- include Loggable
11
+ include Logue::Loggable
10
12
 
11
13
  def initialize fname, range
12
14
  @fname = fname
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
+ require 'rubygems'
5
+ require 'logue/loggable'
4
6
  require 'glark/io/file/archive_file'
5
7
 
6
8
  module Glark
7
9
  class ZipFile < ArchiveFile
8
- include Loggable
10
+ include Logue::Loggable
9
11
 
10
12
  def initialize fname, range, &blk
11
13
  super fname, range
@@ -5,15 +5,12 @@
5
5
  # Distance for and expression
6
6
 
7
7
  require 'rubygems'
8
- require 'riel/string'
9
8
  require 'glark/match/re'
10
9
  require 'glark/match/ior'
11
10
  require 'glark/match/xor'
12
11
  require 'glark/match/and'
13
12
 
14
13
  class AndDistance
15
- include Loggable
16
-
17
14
  # signifies no limit to the distance between matches, i.e., anywhere within
18
15
  # the entire file is valid.
19
16
  INFINITE_DISTANCE = -1
@@ -53,6 +50,12 @@ class AndDistance
53
50
  end
54
51
 
55
52
  def numeric? x
56
- x && (x.kind_of?(Fixnum) || x.to_i == INFINITE_DISTANCE || x.num)
53
+ return nil unless x
54
+ return true if x.kind_of?(Fixnum) || x.to_i == INFINITE_DISTANCE
55
+ begin
56
+ Integer x
57
+ rescue ArgumentError
58
+ nil
59
+ end
57
60
  end
58
61
  end
@@ -4,13 +4,8 @@
4
4
 
5
5
  # Extended regular-expression-based expressions.
6
6
 
7
- require 'rubygems'
8
- require 'riel'
9
-
10
7
  # An expression, which can be applied (processed) against a Glark::File.
11
8
  class Expression
12
- include Loggable
13
-
14
9
  attr_accessor :matches
15
10
 
16
11
  def initialize
@@ -6,7 +6,7 @@
6
6
 
7
7
  require 'rubygems'
8
8
  require 'riel/regexp'
9
- require 'riel/log/loggable'
9
+ require 'logue/loggable'
10
10
  require 'glark/match/and'
11
11
  require 'glark/match/and_distance'
12
12
  require 'glark/match/ior'
@@ -14,7 +14,7 @@ require 'glark/match/re_factory'
14
14
  require 'glark/match/xor'
15
15
 
16
16
  class ExpressionFactory
17
- include Loggable
17
+ include Logue::Loggable
18
18
 
19
19
  attr_reader :expr
20
20
 
@@ -5,7 +5,6 @@
5
5
  # Options for matching.
6
6
 
7
7
  require 'rubygems'
8
- require 'riel/log'
9
8
  require 'glark/match/spec'
10
9
  require 'glark/util/options'
11
10
 
@@ -5,11 +5,12 @@
5
5
  # RegexpExpression factory.
6
6
 
7
7
  require 'rubygems'
8
+ require 'logue/loggable'
8
9
  require 'riel/regexp'
9
10
  require 'glark/match/re'
10
11
 
11
12
  class RegexpExpressionFactory
12
- include Loggable
13
+ include Logue::Loggable
13
14
 
14
15
  attr_reader :count
15
16
 
@@ -5,7 +5,6 @@
5
5
  # Options for matching.
6
6
 
7
7
  require 'rubygems'
8
- require 'riel/log'
9
8
  require 'glark/match/factory'
10
9
  require 'glark/util/colors/spec'
11
10
 
@@ -3,12 +3,13 @@
3
3
 
4
4
  module Glark
5
5
  class Context
6
+ include Logue::Loggable
7
+
6
8
  attr_accessor :after
7
9
  attr_accessor :before
8
10
 
9
- def initialize
10
- @after = 0
11
- @before = 0
11
+ def initialize
12
+ clear
12
13
  end
13
14
 
14
15
  def clear
@@ -31,11 +32,11 @@ module Glark
31
32
 
32
33
  def add_as_option optdata
33
34
  optdata << {
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 },
35
+ :tags => %w{ -C --context },
36
+ :regexp => %r{ ^ - ([1-9]\d*) $ }x,
37
+ :arg => [ :optional, :integer ],
38
+ :process => Proc.new { |val, opt, args| @after = @before = val == true ? 2 : val },
39
+ :rcname => %w{ context },
39
40
  }
40
41
 
41
42
  optdata << {
@@ -54,4 +55,3 @@ module Glark
54
55
  end
55
56
  end
56
57
  end
57
-
@@ -5,7 +5,7 @@
5
5
  require 'glark/util/highlight'
6
6
 
7
7
  class FileHeader
8
- include Loggable, Highlight
8
+ include Highlight
9
9
 
10
10
  def initialize name, highlighter
11
11
  @name = name
@@ -9,7 +9,7 @@ module Glark; end
9
9
 
10
10
  module Glark
11
11
  module Format
12
- include Loggable, Highlight
12
+ include Highlight
13
13
 
14
14
  def initialize file, spec
15
15
  @file_header = nil # not nil after file header written
@@ -90,7 +90,7 @@ module Glark
90
90
  optdata << {
91
91
  :tags => %w{ -u --highlight },
92
92
  :arg => [ :optional, :regexp, %r{ ^ (?:(multi|single)|none) $ }x ],
93
- :set => Proc.new { |md| val = md ? md[1] : "multi"; @colors.text_color_style = val }
93
+ :set => Proc.new { |md| val = md ? md : "multi"; @colors.text_color_style = val }
94
94
  }
95
95
 
96
96
  optdata << {
@@ -5,8 +5,6 @@
5
5
  # Results of searching files.
6
6
 
7
7
  class Results
8
- include Loggable
9
-
10
8
  attr_reader :count
11
9
 
12
10
  def initialize
@@ -46,11 +46,7 @@ module Glark
46
46
  end
47
47
 
48
48
  def make_color color
49
- @highlighter.make_color color
50
- end
51
-
52
- def make_rgb_color red, green, blue, fgbg
53
- @highlighter.make_rgb_color red, green, blue, fgbg
49
+ @highlighter.to_codes color
54
50
  end
55
51
 
56
52
  def make_colors limit = -1
@@ -70,7 +66,7 @@ module Glark
70
66
  def text_color_style= tcstyle
71
67
  @text_color_style = tcstyle
72
68
  if @text_color_style
73
- @highlighter = @text_color_style && HlWrapper.new
69
+ @highlighter = @text_color_style && RainbowHighlighter.instance
74
70
  @text_colors = case @text_color_style
75
71
  when highlight_multi?(@text_color_style), true
76
72
  multi_colors
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- require 'rubygems'
5
- require 'riel/log/loggable'
6
-
7
4
  module Glark
8
5
  class ColorSpec
9
- include Loggable
10
-
11
6
  attr_accessor :text_colors
12
7
  attr_accessor :file_name_color
13
8
  attr_accessor :line_number_color
@@ -75,17 +75,3 @@ class RainbowHighlighter
75
75
  end.join ''
76
76
  end
77
77
  end
78
-
79
- class HlWrapper
80
- def initialize
81
- @hl = RainbowHighlighter.instance
82
- end
83
-
84
- def make_color color
85
- @hl.to_codes color
86
- end
87
-
88
- def make_rgb_color red, green, blue, fgbg
89
- @hl.instance.to_rgb_code red, green, blue, fgbg
90
- end
91
- end
@@ -3,13 +3,14 @@
3
3
  # vim: set filetype=ruby : set sw=2
4
4
 
5
5
  require 'rubygems'
6
+ require 'logue/loggable'
6
7
  require 'glark/util/io/depth'
7
8
  require 'riel/filetype'
8
9
 
9
10
  module Glark
10
11
  # Files and directories. And standard input, just for fun.
11
12
  class FileSet
12
- include Loggable, Enumerable
13
+ include Logue::Loggable, Enumerable
13
14
 
14
15
  attr_reader :files
15
16
 
@@ -111,18 +112,18 @@ module Glark
111
112
  subdepth = depth - 1
112
113
 
113
114
  pn.children.sort.each do |entry|
114
- next if @yielded_files.include?(entry)
115
115
  if entry.file?
116
116
  type = FileType.type entry.to_s
117
117
  next if type == FileType::BINARY && @binary_files == 'skip'
118
118
  end
119
- @yielded_files << entry
120
119
  handle_pathname entry, subdepth, &blk
121
120
  end
122
121
  end
123
122
 
124
123
  def handle_file pn, &blk
125
124
  return if @file_criteria.skipped? pn
125
+ return if @yielded_files.include? pn
126
+ @yielded_files << pn
126
127
 
127
128
  type = FileType.type pn.to_s
128
129
  case type
@@ -2,11 +2,13 @@
2
2
  #!ruby -w
3
3
  # vim: set filetype=ruby : set sw=2
4
4
 
5
+ require 'rubygems'
6
+ require 'logue/loggable'
5
7
  require 'glark/util/io/filter/filter'
6
8
 
7
9
  module Glark
8
10
  class Criteria
9
- include Loggable
11
+ include Logue::Loggable
10
12
 
11
13
  def initialize
12
14
  # by type (hash) => by positive/negative (hash) => filter list (array)
@@ -4,8 +4,6 @@
4
4
 
5
5
  module Glark
6
6
  class Option
7
- include Loggable
8
-
9
7
  def initialize optee
10
8
  @optee = optee
11
9
  end
@@ -3,10 +3,10 @@
3
3
  # vim: set filetype=ruby : set sw=2
4
4
 
5
5
  require 'glark/util/optutil'
6
- require 'riel/log/loggable'
6
+ require 'logue/loggable'
7
7
 
8
8
  module Glark
9
9
  class Options
10
- include Loggable, Glark::OptionUtil
10
+ include Logue::Loggable, Glark::OptionUtil
11
11
  end
12
12
  end