Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 768f9fdbee39
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 717195694bfe
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 14, 2016

  1. Add concept of "features" to arg processing and hook up --enable

    This fixes MRI's TestRubyOptions#test_enable.
    headius committed Mar 14, 2016
    Copy the full SHA
    ef64d7e View commit details
  2. Copy the full SHA
    7171956 View commit details
Showing with 63 additions and 43 deletions.
  1. +63 −41 core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
  2. +0 −2 test/mri/excludes/TestRubyOptions.rb
104 changes: 63 additions & 41 deletions core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
@@ -36,13 +36,16 @@
import org.jruby.util.FileResource;
import org.jruby.util.KCode;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.func.Function2;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.regex.Pattern;
@@ -505,57 +508,24 @@ private void processArgument() {
} else if (argument.equals("--debug-frozen-string-literal")) {
config.setDebuggingFrozenStringLiteral(true);
break FOR;
} else if (argument.equals("--disable-gems")) {
config.setDisableGems(true);
break FOR;
} else if (argument.equals("--disable-did_you_mean")) {
config.setDisableDidYouMean(true);
break FOR;
} else if (argument.equals("--disable-frozen-string-literal")) {
config.setFrozenStringLiteral(false);
break FOR;
} else if (argument.startsWith("--disable")) {
if (argument.equals("--disable")) {
characterIndex = argument.length();
String feature = grabValue(getArgumentError("missing argument for --disable"), false);
argument = "--disable=" + feature;
}
for (String disable : valueListFor(argument, "disable")) {
boolean all = disable.equals("all");
if (disable.equals("gems") || all) {
config.setDisableGems(true);
continue;
}
if (disable.equals("did_you_mean") || all) {
config.setDisableDidYouMean(true);
continue;
}
if (disable.equals("rubyopt") || all) {
config.setDisableRUBYOPT(true);
continue;
}
if (disable.equals("frozen-string-literal") || disable.equals("frozen_string_literal") || all) {
config.setFrozenStringLiteral(false);
continue;
}

config.getError().println("warning: unknown argument for --disable: `" + disable + "'");
enableDisableFeature(disable, false);
}
break FOR;
} else if (argument.equals("--enable")) {
errorMissingEquals("enable");
} else if (argument.equals("--enable-frozen-string-literal")) {
config.setFrozenStringLiteral(true);
break FOR;
} else if (argument.startsWith("--enable=")) {
} else if (argument.startsWith("--enable")) {
if (argument.equals("--enable")) {
characterIndex = argument.length();
String feature = grabValue(getArgumentError("missing argument for --enable"), false);
argument = "--enable=" + feature;
}
for (String enable : valueListFor(argument, "enable")) {
boolean all = enable.equals("all");
if (enable.equals("frozen-string-literal") || enable.equals("frozen_string_literal") || all) {
config.setFrozenStringLiteral(true);
continue;
}

config.getError().println("warning: unknown argument for --enable: `" + enable + "'");
enableDisableFeature(enable, true);
}
break FOR;
} else if (argument.equals("--gemfile")) {
@@ -621,6 +591,16 @@ private void processArgument() {
}
}

private void enableDisableFeature(String name, boolean enable) {
Function2<Boolean, ArgumentProcessor, Boolean> feature = FEATURES.get(name);

if (feature == null) {
config.getError().println("warning: unknown argument for --" + (enable ? "enable" : "disable") + ": `" + name + "'");
} else {
feature.apply(this, enable);
}
}

private String[] valueListFor(String argument, String key) {
int length = key.length() + 3; // 3 is from -- and = (e.g. --disable=)
String[] values = argument.substring(length).split(",");
@@ -817,4 +797,46 @@ private boolean isPropertySupported(String propertyName) {
return false;
}

private static final Map<String, Function2<Boolean, ArgumentProcessor, Boolean>> FEATURES;

static {
Map<String, Function2<Boolean, ArgumentProcessor, Boolean>> features = new HashMap<>();

features.put("all", new Function2<Boolean, ArgumentProcessor, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
// disable all features
for (Map.Entry<String, Function2<Boolean, ArgumentProcessor, Boolean>> entry : FEATURES.entrySet()) {
if (entry.getKey().equals("all")) continue; // skip self
entry.getValue().apply(processor, enable);
}
return true;
}
});
features.put("gems", new Function2<Boolean, ArgumentProcessor, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setDisableGems(!enable);
return true;
}
});
features.put("did_you_mean", new Function2<Boolean, ArgumentProcessor, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setDisableDidYouMean(!enable);
return true;
}
});
features.put("rubyopt", new Function2<Boolean, ArgumentProcessor, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setDisableRUBYOPT(!enable);
return true;
}
});
features.put("frozen-string-literal", new Function2<Boolean, ArgumentProcessor, Boolean>() {
public Boolean apply(ArgumentProcessor processor, Boolean enable) {
processor.config.setFrozenStringLiteral(enable);
return true;
}
});

FEATURES = features;
}
}
2 changes: 0 additions & 2 deletions test/mri/excludes/TestRubyOptions.rb
Original file line number Diff line number Diff line change
@@ -2,10 +2,8 @@
exclude :test_chdir, "needs investigation"
exclude :test_copyright, "needs investigation"
exclude :test_debug, "needs investigation"
exclude :test_disable, "needs investigation"
exclude :test_dump_syntax_with_rflag, "needs investigation"
exclude :test_dump_yydebug_with_rflag, "needs investigation"
exclude :test_enable, "needs investigation"
exclude :test_encoding, "needs investigation"
exclude :test_eval, "needs investigation"
exclude :test_indentation_check, "needs investigation"