Class: Grepresent::CLI
- Inherits:
-
Object
- Object
- Grepresent::CLI
- Defined in:
- lib/grepresent/cli.rb
Instance Attribute Summary collapse
-
#debug_mode ⇒ Object
readonly
Returns the value of attribute debug_mode.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Attribute Details
#debug_mode ⇒ Object (readonly)
Returns the value of attribute debug_mode.
7 8 9 |
# File 'lib/grepresent/cli.rb', line 7 def debug_mode @debug_mode end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
6 7 8 |
# File 'lib/grepresent/cli.rb', line 6 def rules @rules end |
Class Method Details
.run! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/grepresent/cli.rb', line 9 def self.run! @dry_run = false @rules = [] OptionParser.new do |opts| opts. = "Usage: grepresent [ options ]" # opts << Option.new(:name => [ '-f', '--format PATTERN FORMAT', [1,1] ], # :arg_arity => [2,2]) opts.on("-f", "--format PATTERN FORMAT", "Specify a format") do |p| f = ARGV.shift @rules << Grepresent::FormatterRule.new(p, f) end opts.on('-d', '--dry-run', "Output all parsed rules, but don't process any input") do @dry_run = true end opts.on("-h", "--help") do puts opts exit end end.parse! end |
.start ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/grepresent/cli.rb', line 35 def self.start if @dry_run @rules.each do |r| puts "#{ r.pattern.inspect } => #{ r.format } (#{ r.formats }SAMPLE#{ Term::ANSIColor.reset })" end return end $stdin.each do |line| @rules.each { |r| line = r.apply(line) } puts line end end |