Class: Bake::BakeFormatOptions

Inherits:
Parser
  • Object
show all
Defined in:
lib/format/options/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#add_option, #get_block, #num_parameter?, #parse_internal, #valid?

Constructor Details

#initialize(argv) ⇒ BakeFormatOptions

Returns a new instance of BakeFormatOptions.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/format/options/options.rb', line 10

def initialize(argv)
  super(argv)

  @input = '-'
  @output = '-'
  @start_line = nil
  @end_line = nil
  @indent = '  '
  @index = 0

  add_option([""             ], lambda { |x| collect_args(x)                                      })
  add_option(["--indent"     ], lambda { |x| @indent = x                                          })
  add_option(["--lines"      ], lambda { |x| set_lines(x)                                         })
  add_option(["-h", "--help" ], lambda { usage; ExitHelper.exit(0)                                })
  add_option(["--version"    ], lambda { Bake::Version.printBakeFormatVersion; ExitHelper.exit(0) })
end

Instance Attribute Details

#end_lineObject (readonly)

Fixnum



8
9
10
# File 'lib/format/options/options.rb', line 8

def end_line
  @end_line
end

#indentObject (readonly)

String



7
8
9
# File 'lib/format/options/options.rb', line 7

def indent
  @indent
end

#inputObject (readonly)

String



7
8
9
# File 'lib/format/options/options.rb', line 7

def input
  @input
end

#outputObject (readonly)

String



7
8
9
# File 'lib/format/options/options.rb', line 7

def output
  @output
end

#start_lineObject (readonly)

Fixnum



8
9
10
# File 'lib/format/options/options.rb', line 8

def start_line
  @start_line
end

Instance Method Details

#parse_optionsObject



38
39
40
# File 'lib/format/options/options.rb', line 38

def parse_options()
  parse_internal(true)
end

#usageObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/format/options/options.rb', line 27

def usage
  puts [
    "Usage: #{__FILE__} [--indent=string] [--lines=string] input output",
    "  --indent=string, indent defaults to two spaces.",
    "    Note, you can escape a tab in bash by ctrl-vTAB with sourrounding \" e.g. \"--input=    \"",
    "  --lines=string, [start line]:[end line] - format a range of lines.",
    "  input, filename or '-' for stdin",
    "  output, filename, '-' for stdout, '--' for same as input file"
  ].join("\n")
end