} else {
try {
int val = Integer.parseInt(temp, 8);
config.setRecordSeparator("" + (char) val);
} catch (Exception e) {
MainExitException mee = new MainExitException(1, getArgumentError(" -0 must be followed by either 0, 777, or a valid octal value"));
mee.setUsageError(true);
throw mee;
}
}
break FOR;
}
case 'a':
config.setSplit(true);
break;
case 'b':
config.setBenchmarking(true);
break;
case 'c':
config.setShouldCheckSyntax(true);
break;
case 'C':
try {
String saved = grabValue(getArgumentError(" -C must be followed by a directory expression"));
File base = new File(config.getCurrentDirectory());
File newDir = new File(saved);
if (newDir.isAbsolute()) {
config.setCurrentDirectory(newDir.getCanonicalPath());
} else {
config.setCurrentDirectory(new File(base, newDir.getPath()).getCanonicalPath());
}
if (!(new File(config.getCurrentDirectory()).isDirectory())) {
MainExitException mee = new MainExitException(1, "jruby: Can't chdir to " + saved + " (fatal)");
throw mee;
}
} catch (IOException e) {
MainExitException mee = new MainExitException(1, getArgumentError(" -C must be followed by a valid directory"));
throw mee;
}
break FOR;
case 'd':
config.setDebug(true);
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
break;
case 'e':
config.getInlineScript().append(grabValue(getArgumentError(" -e must be followed by an expression to evaluate")));
config.getInlineScript().append('\n');
config.setHasInlineScript(true);
break FOR;
case 'E':
processEncodingOption(grabValue(getArgumentError("unknown encoding name")));
break FOR;
case 'F':
config.setInputFieldSeparator(grabValue(getArgumentError(" -F must be followed by a pattern for input field separation")));
break FOR;
case 'h':
config.setShouldPrintUsage(true);
config.setShouldRunInterpreter(false);
break;
case 'i':
config.setInPlaceBackupExtension(grabOptionalValue());
if (config.getInPlaceBackupExtension() == null) {
config.setInPlaceBackupExtension("");
}
break FOR;
case 'I':
String s = grabValue(getArgumentError("-I must be followed by a directory name to add to lib path"));
String[] ls = s.split(java.io.File.pathSeparator);
config.getLoadPaths().addAll(Arrays.asList(ls));
break FOR;
case 'J':
grabOptionalValue();
config.getError().println("warning: " + argument + " argument ignored (launched in same VM?)");
break FOR;
case 'K':
// FIXME: No argument seems to work for -K in MRI plus this should not
// siphon off additional args 'jruby -K ~/scripts/foo'. Also better error
// processing.
String eArg = grabValue(getArgumentError("provide a value for -K"));
config.setKCode(KCode.create(null, eArg));
break;
case 'l':
config.setProcessLineEnds(true);
break;
case 'n':
config.setAssumeLoop(true);
break;
case 'p':
config.setAssumePrinting(true);
config.setAssumeLoop(true);
break;
case 'r':
config.getRequiredLibraries().add(grabValue(getArgumentError("-r must be followed by a package to require")));
break FOR;
case 's':
config.setArgvGlobalsOn(true);
break;
case 'G':
config.setLoadGemfile(true);
break;
case 'S':
runBinScript();
break FOR;
case 'T':
{
String temp = grabOptionalValue();
break FOR;
}
case 'U':
config.setInternalEncoding("UTF-8");
break;
case 'v':
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
config.setShowVersion(true);
break;
case 'w':
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
break;
case 'W':
{
String temp = grabOptionalValue();
int value = 2;
if (null != temp) {
if (temp.equals("2")) {
value = 2;
} else if (temp.equals("1")) {
value = 1;
} else if (temp.equals("0")) {
value = 0;
} else {
MainExitException mee = new MainExitException(1, getArgumentError(" -W must be followed by either 0, 1, 2 or nothing"));
mee.setUsageError(true);
throw mee;
}
}
switch (value) {
case 0:
config.setVerbosity(RubyInstanceConfig.Verbosity.NIL);
break;
case 1:
config.setVerbosity(RubyInstanceConfig.Verbosity.FALSE);
break;
case 2:
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
break;
}
break FOR;
}
case 'x':
try {
String saved = grabOptionalValue();
if (saved != null) {
File base = new File(config.getCurrentDirectory());
File newDir = new File(saved);
if (newDir.isAbsolute()) {
config.setCurrentDirectory(newDir.getCanonicalPath());
} else {
config.setCurrentDirectory(new File(base, newDir.getPath()).getCanonicalPath());
}
if (!(new File(config.getCurrentDirectory()).isDirectory())) {
MainExitException mee = new MainExitException(1, "jruby: Can't chdir to " + saved + " (fatal)");
throw mee;
}
}
config.setXFlag(true);
} catch (IOException e) {
MainExitException mee = new MainExitException(1, getArgumentError(" -x must be followed by a valid directory"));
throw mee;
}
break FOR;
case 'X':
String extendedOption = grabOptionalValue();
if (extendedOption == null) {
if (SafePropertyAccessor.getBoolean("jruby.launcher.nopreamble", false)) {
throw new MainExitException(0, OutputStrings.getExtendedHelp());
} else {
throw new MainExitException(0, "jruby: missing argument\n" + OutputStrings.getExtendedHelp());
}
} else if (extendedOption.equals("-O")) {
config.setObjectSpaceEnabled(false);
} else if (extendedOption.equals("+O")) {
config.setObjectSpaceEnabled(true);
} else if (extendedOption.equals("-C")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.OFF);
} else if (extendedOption.equals("-CIR")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.OFFIR);
} else if (extendedOption.equals("+C")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.FORCE);
} else if (extendedOption.equals("+CIR")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.FORCEIR);
} else {
MainExitException mee = new MainExitException(1, "jruby: invalid extended option " + extendedOption + " (-X will list valid options)\n");
mee.setUsageError(true);
throw mee;
}
break FOR;
case 'y':
config.setParserDebug(true);
break FOR;
case '-':
if (argument.equals("--command") || argument.equals("--bin")) {
characterIndex = argument.length();
runBinScript();
break;
} else if (argument.equals("--compat")) {
characterIndex = argument.length();
config.setCompatVersion(CompatVersion.getVersionFromString(grabValue(getArgumentError("--compat must be RUBY1_8 or RUBY1_9"))));
break FOR;
} else if (argument.equals("--copyright")) {
config.setShowCopyright(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (argument.equals("--debug")) {
RubyInstanceConfig.FULL_TRACE_ENABLED = true;
config.setCompileMode(RubyInstanceConfig.CompileMode.OFF);
break FOR;
} else if (argument.equals("--jdb")) {
config.setDebug(true);
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
break;
} else if (argument.equals("--help")) {
config.setShouldPrintUsage(true);
config.setShouldRunInterpreter(false);
break;
} else if (argument.equals("--properties")) {
config.setShouldPrintProperties(true);
config.setShouldRunInterpreter(false);
break;
} else if (argument.equals("--version")) {
config.setShowVersion(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (argument.equals("--bytecode")) {
config.setShowBytecode(true);
break FOR;
} else if (argument.equals("--fast")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.FORCE);
break FOR;
} else if (argument.startsWith("--profile")) {
characterIndex = argument.length();
int dotIndex = argument.indexOf(".");
if (dotIndex == -1) {
config.setProfilingMode(RubyInstanceConfig.ProfilingMode.FLAT);
} else {
String profilingMode = argument.substring(dotIndex + 1, argument.length());
if (profilingMode.equals("out")) {
// output file for profiling results
String outputFile = grabValue(getArgumentError("--profile.out requires an output file argument"));
try {
config.setProfileOutput(new ProfileOutput(new File(outputFile)));
} catch (FileNotFoundException e) {
throw new MainExitException(1, String.format("jruby: %s", e.getMessage()));
}
} else {
try {
config.setProfilingMode(RubyInstanceConfig.ProfilingMode.valueOf(profilingMode.toUpperCase()));
} catch (IllegalArgumentException e) {
throw new MainExitException(1, String.format("jruby: unknown profiler mode \"%s\"", profilingMode));
}
}
}
break FOR;
} else if (argument.equals("--1.9")) {
config.setCompatVersion(CompatVersion.RUBY1_9);
break FOR;
} else if (argument.equals("--2.0")) {
config.setCompatVersion(CompatVersion.RUBY2_0);
break FOR;
} else if (argument.equals("--1.8")) {
config.setCompatVersion(CompatVersion.RUBY1_8);
break FOR;
} else if (argument.equals("--disable-gems")) {
config.setDisableGems(true);
break FOR;
} else if (argument.equals("--gemfile")) {
config.setLoadGemfile(true);
break FOR;
} else if (argument.equals("--dump")) {
characterIndex = argument.length();
String error = "--dump only supports [version, copyright, usage, yydebug, syntax, insns] on JRuby";
String dumpArg = grabValue(getArgumentError(error));
if (dumpArg.equals("version")) {
config.setShowVersion(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (dumpArg.equals("copyright")) {
config.setShowCopyright(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (dumpArg.equals("usage")) {
config.setShouldPrintUsage(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (dumpArg.equals("yydebug")) {
config.setParserDebug(true);
break FOR;
} else if (dumpArg.equals("syntax")) {
config.setShouldCheckSyntax(true);
} else if (dumpArg.equals("insns")) {
config.setShowBytecode(true);
} else {
MainExitException mee = new MainExitException(1, error);
mee.setUsageError(true);
throw mee;
}
break;
} else {
if (argument.equals("--")) {
// ruby interpreter compatibilty
// Usage: ruby [switches] [--] [programfile] [arguments])
endOfArguments = true;
break;
}
}
default:
throw new MainExitException(1, "jruby: unknown option " + argument);
}
}
}