Class: ByebugCleaner::ArgumentParser::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/byebug/cleaner/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



7
8
9
10
11
# File 'lib/byebug/cleaner/parser.rb', line 7

def initialize
  self.dir = "app"
  self.backup = true
  self.test = 0
end

Instance Attribute Details

#backupObject

Returns the value of attribute backup.



5
6
7
# File 'lib/byebug/cleaner/parser.rb', line 5

def backup
  @backup
end

#dirObject

Returns the value of attribute dir.



5
6
7
# File 'lib/byebug/cleaner/parser.rb', line 5

def dir
  @dir
end

#testObject

Returns the value of attribute test.



5
6
7
# File 'lib/byebug/cleaner/parser.rb', line 5

def test
  @test
end

Instance Method Details

#boolean_backup_option(parser) ⇒ Object



56
57
58
59
60
61
# File 'lib/byebug/cleaner/parser.rb', line 56

def boolean_backup_option(parser)
  # Boolean switch.
  parser.on("-b", "--[no-]backup", "Backup files") do |b|
    self.backup = b
  end
end

#define_options(parser) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/byebug/cleaner/parser.rb', line 13

def define_options(parser)
  parser.banner = "Usage: rake byebug:clean -- [options]"
  parser.separator "Task recursively search files where 'byebug' uses and remove this line from file."
  parser.separator ""
  parser.separator "Default options:"
  parser.separator "	Dir - {RAILS_APP}/app"
  parser.separator "	Backup - true"
  parser.separator ""
  parser.separator "Specific options:"

  # add additional options
  dir_option(parser)
  boolean_backup_option(parser)

  parser.separator ""
  parser.separator "Common options:"
  # No argument, shows at tail.  This will print an options summary.
  # Try it and see!
  			parser.on("-h", "--help", "Prints this help") do
puts parser
exit
  			end
  # Another typical switch to print the version.
  parser.on("-v", "Show version") do
    puts VERSION
    exit
  end
  parser.separator ""
  parser.separator "Examples:"
  parser.separator "	rake byebug:clean"
  parser.separator "	rake byebug:clean -- -dspec"
  parser.separator "	rake byebug:clean -- --dir=app/models --no-debug"
end

#dir_option(parser) ⇒ Object



48
49
50
51
52
53
# File 'lib/byebug/cleaner/parser.rb', line 48

def dir_option(parser)
  # Cast 'time' argument to a Time object.
  parser.on("-dDIR", "--dir=DIR", String, "Set dir for searching") do |dir|
    self.dir = dir
  end
end