Module: Rcodetools::OptionHandler

Defined in:
lib/rcodetools/options.rb

Overview

Domain specific OptionParser extensions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.auto_include_paths(include_paths, pwd) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/rcodetools/options.rb', line 86

def auto_include_paths(include_paths, pwd)
  if pwd =~ %r!^(.+)/(lib|bin)!
    include_paths.unshift("#$1/lib").unshift("#$1/bin")
  elsif File.file? "#{pwd}/Rakefile" or File.file? "#{pwd}/rakefile"
    include_paths.unshift("#{pwd}/lib").unshift("#{pwd}/bin")
  end
end

Instance Method Details

#handle_interpreter(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rcodetools/options.rb', line 30

def handle_interpreter(options)
  separator ""
  separator "Interpreter options:"
  on("-S FILE", "--interpreter FILE", "Use interpreter FILE.") do |interpreter|
    options[:interpreter] = interpreter
  end
  on("-I PATH", "Add PATH to $LOAD_PATH") do |path|
    options[:include_paths] << path
  end
  on("--dev", "Add this project's bin/ and lib/ to $LOAD_PATH.",
     "A directory with a Rakefile is considered a project base directory.") do
    auto_include_paths(options[:include_paths], Dir.pwd)
  end
  on("-r LIB", "Require LIB before execution.") do |lib|
    options[:libs] << lib
  end
  on("-e EXPR", "--eval=EXPR", "--stub=EXPR", "Evaluate EXPR after execution.") do |expr|
    options[:evals] << expr
  end
  on("--fork", "Use rct-fork-client if rct-fork is running.") do 
    options[:detect_rct_fork] = true
  end
  on("--rbtest", "Use rbtest.") do
    options[:use_rbtest] = true
  end
  on("--detect-rbtest", "Use rbtest if '=begin test_*' blocks exist.") do
    options[:detect_rbtest] = true
  end
end

#handle_misc(options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rcodetools/options.rb', line 60

def handle_misc(options)
  separator ""
  separator "Misc options:"
  on("--cd DIR", "Change working directory to DIR.") do |dir|
    options[:wd] = dir
  end
  on("--debug", "Write transformed source code to xmp-tmp.PID.rb.") do
    options[:dump] = "xmp-tmp.#{Process.pid}.rb"
  end
  on("--tmpfile", "--tempfile", "Use tmpfile instead of open3. (non-windows)") do
    options[:execute_ruby_tmpfile] = true
  end
  on("-w N", "--width N", Integer, "Set width of multi-line annotation. (xmpfilter only)") do |width|
    options[:width] = width
  end
  separator ""
  on("-h", "--help", "Show this message") do
    puts self
    exit
  end
  on("-v", "--version", "Show version information") do
    puts "#{File.basename($0)} #{XMPFilter::VERSION}"
    exit
  end
end

#handle_position(options) ⇒ Object



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

def handle_position(options)
  separator ""
  separator "Position options:"
  on("--line=LINE", "Current line number.") do |n|
    options[:lineno] = n.to_i
  end
  on("--column=COLUMN", "Current column number in BYTE.") do |n|
    options[:column] = n.to_i
  end
  on("-t TEST", "--test=TEST",
     "Execute test script. ",
     "TEST is TESTSCRIPT, TESTSCRIPT@TESTMETHOD, or TESTSCRIPT@LINENO.",
     "You must specify --filename option.") do |t|
    options[:test_script], options[:test_method] = t.split(/@/)
  end
  on("--filename=FILENAME", "Filename of standard input.") do |f|
    options[:filename] = f
  end
end

#set_bannerObject



6
7
8
# File 'lib/rcodetools/options.rb', line 6

def set_banner
  self.banner = "Usage: #{$0} [options] [inputfile] [-- cmdline args]"
end