Module: Rcodetools::OptionHandler
- Defined in:
- lib/rcodetools/options.rb
Overview
Domain specific OptionParser extensions
Class Method Summary collapse
Instance Method Summary collapse
- #handle_interpreter(options) ⇒ Object
- #handle_misc(options) ⇒ Object
- #handle_position(options) ⇒ Object
- #set_banner ⇒ Object
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() separator "" separator "Interpreter options:" on("-S FILE", "--interpreter FILE", "Use interpreter FILE.") do |interpreter| [:interpreter] = interpreter end on("-I PATH", "Add PATH to $LOAD_PATH") do |path| [: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([:include_paths], Dir.pwd) end on("-r LIB", "Require LIB before execution.") do |lib| [:libs] << lib end on("-e EXPR", "--eval=EXPR", "--stub=EXPR", "Evaluate EXPR after execution.") do |expr| [:evals] << expr end on("--fork", "Use rct-fork-client if rct-fork is running.") do [:detect_rct_fork] = true end on("--rbtest", "Use rbtest.") do [:use_rbtest] = true end on("--detect-rbtest", "Use rbtest if '=begin test_*' blocks exist.") do [: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() separator "" separator "Misc options:" on("--cd DIR", "Change working directory to DIR.") do |dir| [:wd] = dir end on("--debug", "Write transformed source code to xmp-tmp.PID.rb.") do [:dump] = "xmp-tmp.#{Process.pid}.rb" end on("--tmpfile", "--tempfile", "Use tmpfile instead of open3. (non-windows)") do [:execute_ruby_tmpfile] = true end on("-w N", "--width N", Integer, "Set width of multi-line annotation. (xmpfilter only)") do |width| [: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() separator "" separator "Position options:" on("--line=LINE", "Current line number.") do |n| [:lineno] = n.to_i end on("--column=COLUMN", "Current column number in BYTE.") do |n| [: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| [:test_script], [:test_method] = t.split(/@/) end on("--filename=FILENAME", "Filename of standard input.") do |f| [:filename] = f end end |
#set_banner ⇒ Object
6 7 8 |
# File 'lib/rcodetools/options.rb', line 6 def self. = "Usage: #{$0} [options] [inputfile] [-- cmdline args]" end |