} 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':
disallowedInRubyOpts(argument);
config.setSplit(true);
break;
case 'c':
disallowedInRubyOpts(argument);
config.setShouldCheckSyntax(true);
break;
case 'C':
disallowedInRubyOpts(argument);
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':
disallowedInRubyOpts(argument);
config.getInlineScript().append(grabValue(getArgumentError(" -e must be followed by an expression to report")));
config.getInlineScript().append('\n');
config.setHasInlineScript(true);
break FOR;
case 'E':
processEncodingOption(grabValue(getArgumentError("unknown encoding name")));
break FOR;
case 'F':
disallowedInRubyOpts(argument);
config.setInputFieldSeparator(grabValue(getArgumentError(" -F must be followed by a pattern for input field separation")));
break FOR;
case 'h':
disallowedInRubyOpts(argument);
config.setShouldPrintUsage(true);
config.setShouldRunInterpreter(false);
break;
case 'i':
disallowedInRubyOpts(argument);
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));
// source encoding
config.setSourceEncoding(config.getKCode().getEncoding().toString());
// set external encoding if not already specified
if (config.getExternalEncoding() == null) {
config.setExternalEncoding(config.getKCode().getEncoding().toString());
}
break;
case 'l':
disallowedInRubyOpts(argument);
config.setProcessLineEnds(true);
break;
case 'n':
disallowedInRubyOpts(argument);
config.setAssumeLoop(true);
config.setKernelGsubDefined(true);
break;
case 'p':
disallowedInRubyOpts(argument);
config.setAssumePrinting(true);
config.setAssumeLoop(true);
config.setKernelGsubDefined(true);
break;
case 'r':
config.getRequiredLibraries().add(grabValue(getArgumentError("-r must be followed by a package to require")));
break FOR;
case 's':
disallowedInRubyOpts(argument);
config.setArgvGlobalsOn(true);
break;
case 'G':
config.setLoadGemfile(true);
break;
case 'S':
disallowedInRubyOpts(argument);
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();
if (temp == null) {
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
} else {
if (temp.equals("0")) {
config.setVerbosity(RubyInstanceConfig.Verbosity.NIL);
} else if (temp.equals("1")) {
config.setVerbosity(RubyInstanceConfig.Verbosity.FALSE);
} else if (temp.equals("2")) {
config.setVerbosity(RubyInstanceConfig.Verbosity.TRUE);
} else {
MainExitException mee = new MainExitException(1, getArgumentError(" -W must be followed by either 0, 1, 2 or nothing"));
mee.setUsageError(true);
throw mee;
}
}
break FOR;
}
case 'x':
disallowedInRubyOpts(argument);
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':
disallowedInRubyOpts(argument);
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") || extendedOption.equals("-CIR")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.OFF);
} else if (extendedOption.equals("+C") || extendedOption.equals("+CIR")) {
config.setCompileMode(RubyInstanceConfig.CompileMode.FORCE);
} else if (extendedOption.equals("+T")) {
checkGraalVersion();
config.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);
config.setDisableGems(true);
Options.PARSER_DETAILED_SOURCE_POSITIONS.force(Boolean.toString(true));
} else if (extendedOption.endsWith("...")) {
Options.listPrefix(extendedOption.substring(0, extendedOption.length() - "...".length()));
config.setShouldRunInterpreter(false);
} else if (extendedOption.endsWith("?")) {
Options.listContains(extendedOption.substring(0, extendedOption.length() - 1));
config.setShouldRunInterpreter(false);
} 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':
disallowedInRubyOpts(argument);
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();
grabValue(getArgumentError("--compat takes an argument, but will be ignored"));
config.getError().println("warning: " + argument + " ignored");
break FOR;
} else if (argument.equals("--copyright")) {
disallowedInRubyOpts(argument);
config.setShowCopyright(true);
config.setShouldRunInterpreter(false);
break FOR;
} else if (argument.equals("--debug")) {
disallowedInRubyOpts(argument);
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")) {
disallowedInRubyOpts(argument);
config.setShouldPrintUsage(true);
config.setShouldRunInterpreter(false);
break;
} else if (argument.equals("--properties")) {
config.setShouldPrintProperties(true);
config.setShouldRunInterpreter(false);
break;
} else if (argument.equals("--version")) {
disallowedInRubyOpts(argument);
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 if (profilingMode.equals("service")) {
// service class name
String service = grabValue(getArgumentError("--profile.service requires an class name argument"));
config.setProfilingMode( RubyInstanceConfig.ProfilingMode.SERVICE);
config.setProfilingService(service);
} 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.8")) {
config.getError().println("warning: " + argument + " ignored");
break FOR;
} else if (argument.equals("--1.9")) {
config.getError().println("warning: " + argument + " ignored");
break FOR;
} else if (argument.equals("--2.0")) {
config.getError().println("warning: " + argument + " ignored");
break FOR;
} else if (argument.equals("--2.1")) {
// keep the switch for consistency
break FOR;
} else if (argument.equals("--disable-gems")) {
config.setDisableGems(true);
break FOR;
} else if (argument.equals("--disable")) {
errorMissingDisable();
} else if (argument.startsWith("--disable=")) {
String disablesStr = argument.substring("--disable=".length());
String[] disables = disablesStr.split(",");
if (disables.length == 0) errorMissingDisable();
for (String disable : disables) {
boolean all = disable.equals("all");
if (disable.equals("gems") || all) {
config.setDisableGems(true);
continue;
}
if (disable.equals("rubyopt") || all) {
config.setDisableRUBYOPT(true);
continue;
}
config.getError().println("warning: unknown argument for --disable: `" + disable + "'");
}
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("--dev")) {
// most we can do after JVM boot
Options.COMPILE_INVOKEDYNAMIC.force("false");
config.setCompileMode(RubyInstanceConfig.CompileMode.OFF);
break FOR;
} else if (argument.equals("--server")) {
// ignore this...can't do anything with it after boot
break FOR;
} else if (argument.equals("--client")) {
// ignore this...can't do anything with it after boot
break FOR;
} else if (argument.equals("--yydebug")) {
disallowedInRubyOpts(argument);
config.setParserDebug(true);
} else {
if (argument.equals("--")) {
// ruby interpreter compatibilty
// Usage: ruby [switches] [--] [programfile] [arguments])
endOfArguments = true;
break;
}
}
default:
throw new MainExitException(1, "jruby: unknown option " + argument);
}
}
}