Class: BitClust::Subcommands::PreprocCommand

Inherits:
BitClust::Subcommand show all
Defined in:
lib/bitclust/subcommands/preproc_command.rb

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#error, #help, #option_error, #parse, #srcdir_root

Constructor Details

#initializePreprocCommand

Returns a new instance of PreprocCommand.


10
11
12
13
14
15
16
17
18
# File 'lib/bitclust/subcommands/preproc_command.rb', line 10

def initialize
  super
  @params = { "version" => "2.0.0" }
  @parser.banner = "Usage: #{File.basename($0, '.*')} <file>..."
  @parser.on('--param=KVPAIR', 'Set parameter by key/value pair.') {|pair|
    key, value = pair.split('=', 2)
    params[key] = value
  }
end

Instance Method Details

#exec(argv, options) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bitclust/subcommands/preproc_command.rb', line 20

def exec(argv, options)
  argv.each do |path|
    File.open(path) {|file|
      Preprocessor.wrap(file, @params).each do |line|
        puts line
      end
    }
  end
rescue WriterError => err
  $stderr.puts err.message
  exit 1
end