Method: Rconftool::Processor#initialize

Defined in:
lib/rconftool.rb

#initialize(argv = nil) ⇒ Processor

Parse command-line options and set the @o options hash



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/rconftool.rb', line 284

def initialize(argv=nil)
  require 'optparse'

  @o = { :strip_regexp => /\.dist\z/ }
  return unless argv
  opts = OptionParser.new do |opts|
    opts.banner = "rconftool version #{VERSION}"
    opts.separator "Usage: #{$0} [options]"
    opts.separator ""
    opts.separator "Specific options:"

    opts.on("-n", "--noclobber", "Dummy run") do
      @o[:noclobber] = true
    end
    opts.on("-f", "--force", "Update files even if VERSION is same") do
      @o[:force] = true
    end
    opts.on("-q", "--quiet", "No progress reporting") do
      @o[:debug] = ""
    end
    opts.on("--targetdir DIR", "Where to write merged config files") do |dir|
      @o[:targetdir] = dir
    end
    opts.on("--olddir DIR", "If file does not exist in targetdir,",
            "try to merge from here") do |dir|
      @o[:olddir] = dir
    end
    opts.on("--[no-]recursive", "Traverse directories recursively") do |v|
      @o[:recursive] = v
    end
    opts.on("--strip-suffix FOO", "Remove suffix FOO from target filenames",
    "(default .dist)") do |suffix|
      @o[:strip_regexp] = /#{Regexp.escape(suffix)}\z/
    end
    opts.on("-a", "--add-suffix FOO", "Add suffix FOO to target filenames") do |suffix|
      @o[:add_suffix] = suffix
    end

    opts.on_tail("-?", "--help", "Show this message") do
      puts opts
      exit
    end
  end
  opts.parse!(argv)
end