Class: Glark::OutputOptions
- Inherits:
-
OutputSpec
- Object
- OutputSpec
- Glark::OutputOptions
- Includes:
- OptionUtil
- Defined in:
- lib/glark/output/options.rb
Constant Summary
Constants included from OptionUtil
Instance Attribute Summary
Attributes inherited from OutputSpec
#colors, #context, #count, #file_names_only, #filter, #invert_match, #label, #match_limit, #out, #show_file_names, #show_line_numbers, #style, #write_null
Instance Method Summary collapse
- #add_as_options(optdata) ⇒ Object
- #config_fields ⇒ Object
- #dump_fields ⇒ Object
-
#initialize(colors, optdata) ⇒ OutputOptions
constructor
A new instance of OutputOptions.
- #update_fields(fields) ⇒ Object
Methods included from OptionUtil
#add_opt, #add_opt_arg, #add_opt_blk, #add_opt_false, #add_opt_int, #add_opt_str, #add_opt_true, #colorize, #set, #set_var, #to_boolean
Methods inherited from OutputSpec
#create_output_type, #file_highlight, #highlight, #line_number_highlight, #output_type_cls, #set_file_names_only
Constructor Details
#initialize(colors, optdata) ⇒ OutputOptions
Returns a new instance of OutputOptions.
12 13 14 15 16 |
# File 'lib/glark/output/options.rb', line 12 def initialize colors, optdata super colors optdata end |
Instance Method Details
#add_as_options(optdata) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/glark/output/options.rb', line 56 def optdata @context.add_as_option optdata add_opt_true optdata, :invert_match, %w{ -v --invert-match } add_opt_true optdata, :filter, %w{ --filter } add_opt_false optdata, :filter, %w{ --no-filter --nofilter } add_opt_true optdata, :show_line_numbers, %w{ -n --line-number } add_opt_false optdata, :show_line_numbers, %w{ -N --no-line-number } add_opt_blk(optdata, %w{ -l --files-with-matches }) { set_file_names_only false } add_opt_blk(optdata, %w{ -L --files-without-match }) { set_file_names_only true } add_opt_true optdata, :write_null, %w{ -Z --null } add_opt_str optdata, :label, %w{ --label } add_opt_int optdata, :match_limit, %w{ -m --match-limit } add_opt_blk(optdata, %w{ -U --no-highlight }) { @colors.text_color_style = nil } add_opt_blk(optdata, %w{ -g --grep }) { self.style = "grep" } optdata << { :tags => %w{ --line-number-color }, :arg => [ :string ], :set => Proc.new { |val| @colors.line_number_color = @colors.create_color "line-number-color", val }, } add_opt_true optdata, :count, %w{ -c --count } add_opt_true optdata, :show_file_names, %w{ -H --with-filename } add_opt_false optdata, :show_file_names, %w{ -h --no-filename } optdata << { :tags => %w{ -u --highlight }, :arg => [ :optional, :regexp, %r{ ^ (?:(multi|single)|none) $ }x ], :set => Proc.new { |md| val = md ? md : "multi"; @colors.text_color_style = val } } optdata << { :tags => %w{ --file-color }, :arg => [ :string ], :set => Proc.new { |val| @colors.file_name_color = @colors.create_color "file-color", val } } end |
#config_fields ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/glark/output/options.rb', line 18 def config_fields { "after-context" => @context.after, "before-context" => @context.before, "filter" => @filter, "output" => @style, } end |
#dump_fields ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/glark/output/options.rb', line 27 def dump_fields { "after" => @context.after, "before" => @context.before, "count" => @count, "file_names_only" => @file_names_only, "filter" => @filter, "invert_match" => @invert_match, "label" => @label, "match_limit" => @match_limit, "output" => @style, "show_file_names" => @show_file_names, "show_line_numbers" => @show_line_numbers, "write_null" => @write_null } end |
#update_fields(fields) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/glark/output/options.rb', line 44 def update_fields fields fields.each do |name, values| case name when "grep" self.style = "grep" if to_boolean values.last when "output" self.style = values.last end end @context.update_fields fields end |