Class: Mirah::Util::ArgumentProcessor
- Inherits:
-
Object
- Object
- Mirah::Util::ArgumentProcessor
- Defined in:
- lib/mirah/util/argument_processor.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#exit_status_code ⇒ Object
(also: #exit?)
Returns the value of attribute exit_status_code.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #help_message ⇒ Object
-
#initialize(state, args) ⇒ ArgumentProcessor
constructor
A new instance of ArgumentProcessor.
- #print_help ⇒ Object
- #print_version ⇒ Object
- #process ⇒ Object
Constructor Details
#initialize(state, args) ⇒ ArgumentProcessor
Returns a new instance of ArgumentProcessor.
23 24 25 26 |
# File 'lib/mirah/util/argument_processor.rb', line 23 def initialize(state, args) @state = state @args = args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
28 29 30 |
# File 'lib/mirah/util/argument_processor.rb', line 28 def args @args end |
#exit_status_code ⇒ Object Also known as: exit?
Returns the value of attribute exit_status_code.
28 29 30 |
# File 'lib/mirah/util/argument_processor.rb', line 28 def exit_status_code @exit_status_code end |
#state ⇒ Object
Returns the value of attribute state.
28 29 30 |
# File 'lib/mirah/util/argument_processor.rb', line 28 def state @state end |
Instance Method Details
#help_message ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mirah/util/argument_processor.rb', line 121 def "#{$0} [flags] <files or -e SCRIPT> -c, --classpath PATH\tAdd PATH to the Java classpath for compilation --bootclasspath PATH\tSet the Java bootclasspath to PATH for compilation --cd DIR\t\tSwitch to the specified DIR before compilation -d, --dest DIR\t\tUse DIR as the dir to place the generated class files -e CODE\t\tCompile or run the inline script following -e \t\t\t (the class will be named \"DashE\") --explicit-packages\tRequire explicit 'package' lines in source -h, --help\t\tPrint this help message -I DIR\t\tAdd DIR to the Ruby load path before running --jvm VERSION\t\tEmit JVM bytecode targeting specified JVM \t\t\t version (1.4, 1.5, 1.6, 1.7) --no-save-extensions\tDon't write macro classes to files --no-color\t\tDon't use color when writing logs -N, --new-backend\tUse the new backend -T, --new-types\tUse the new type system -p, --plugin PLUGIN\trequire 'mirah/plugin/PLUGIN' before running -v, --version\t\tPrint the version of Mirah to the console -V, --verbose\t\tVerbose logging --vmodule logger.name=LEVEL[,...]\t\tSet the Level for the specified Java loggers" end |
#print_help ⇒ Object
116 117 118 119 |
# File 'lib/mirah/util/argument_processor.rb', line 116 def print_help puts state.help_printed = true end |
#print_version ⇒ Object
144 145 146 147 |
# File 'lib/mirah/util/argument_processor.rb', line 144 def print_version puts "Mirah v#{Mirah::VERSION}" state.version_printed = true end |
#process ⇒ Object
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 59 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/mirah/util/argument_processor.rb', line 32 def process state.args = args while args.length > 0 && args[0] =~ /^-/ case args[0] when '--classpath', '-c' args.shift state.classpath = args.shift when '--bootclasspath' args.shift state.bootclasspath = args.shift when '--cd' args.shift Dir.chdir(args.shift) when '--dest', '-d' args.shift state.destination = File.join(File.(args.shift), '') when '-e' break when '--explicit-packages' args.shift Mirah::AST::Script.explicit_packages = true when '--help', '-h' args.shift print_help self.exit_status_code = 0 break when '--jvm' args.shift state.set_jvm_version(args.shift) when '-I' args.shift $: << args.shift when '--plugin', '-p' args.shift plugin = args.shift require "mirah/plugin/#{plugin}" when '--verbose', '-V' Mirah::Logging::MirahLogger.level = Mirah::Logging::Level::FINE state.verbose = true args.shift when '--vmodule' args.shift spec = args.shift spec.split(',').each do |item| logger, level = item.split("=") logger = java.util.logging.Logger.getLogger(logger) (state.loggers ||= []) << logger level = java.util.logging.Level.parse(level) logger.setLevel(level) end when '--no-color' args.shift Mirah::Logging::MirahHandler.formatter = Mirah::Logging::LogFormatter.new(false) when '--version', '-v' args.shift print_version self.exit_status_code = 0 if args.empty? break when '--no-save-extensions' args.shift state.save_extensions = false when '--new-backend', '-N' args.shift state.compiler_class = Mirah::JVM::Compiler::Backend when '--new-types', '-T' args.shift java_import 'org.mirah.jvm.mirrors.MirrorTypeSystem' state.type_system = MirrorTypeSystem.new else $stderr.puts "unrecognized flag: " + args[0] self.exit_status_code = 1 break end end return if exit? state.destination ||= File.join(File.('.'), '') state.compiler_class ||= Mirah::JVM::Compiler::JVMBytecode end |