com.github.timm.cucumber.options.RuntimeOptions Maven / Gradle / Ivy
Show all versions of cucumber-jvm-parallel-plugin Show documentation
package com.github.timm.cucumber.options;
import java.util.ArrayList;
import java.util.List;
/**
* Copyright (c) 2008-2014 The Cucumber Organisation.
*
* Fork of https://github.com/cucumber/cucumber-jvm/blob/master/core/src/main/java/cucumber/runtime/RuntimeOptions.java
*/
public class RuntimeOptions {
private final List glue = new ArrayList();
private final List filters = new ArrayList();
private final List pluginNames = new ArrayList();
private Boolean dryRun = null;
private Boolean strict = null;
private Boolean monochrome = null;
/**
* Create a new instance from a string of options, for example:
*
*
* "--name 'the fox' --plugin pretty --strict"
*
*
* @param argv the arguments
*/
public RuntimeOptions(final String argv) {
this(Shellwords.parse(argv));
}
/**
* Create a new instance from a list of options, for example:
*
*
* Arrays.asList("--name", "the fox", "--plugin", "pretty", "--strict");
*
*
* @param argv the arguments
*/
public RuntimeOptions(List argv) {
argv = new ArrayList(argv); // in case the one passed in is unmodifiable.
parse(argv);
}
private void parse(final List args) {
final List parsedFilters = new ArrayList();
// final List parsedFeaturePaths = new ArrayList();
final List parsedGlue = new ArrayList();
while (!args.isEmpty()) {
final String arg = args.remove(0).trim();
if (arg.equals("--glue") || arg.equals("-g")) {
final String gluePath = args.remove(0);
parsedGlue.add(gluePath);
} else if (arg.equals("--tags") || arg.equals("-t")) {
parsedFilters.add(args.remove(0));
} else if (arg.equals("--plugin") || arg.equals("-p")) {
addPluginName(args.remove(0));
} else if (arg.equals("--format") || arg.equals("-f")) {
System.err.println("WARNING: Cucumber-JVM's --format option is deprecated. "
+ "Please use --plugin instead.");
addPluginName(args.remove(0));
} else if (arg.equals("--no-dry-run") || arg.equals("--dry-run") || arg.equals("-d")) {
dryRun = !arg.startsWith("--no-");
} else if (arg.equals("--no-strict") || arg.equals("--strict") || arg.equals("-s")) {
strict = !arg.startsWith("--no-");
} else if (arg.equals("--no-monochrome") || arg.equals("--monochrome")
|| arg.equals("-m")) {
monochrome = !arg.startsWith("--no-");
} else {
// ignore
}
}
if (!parsedFilters.isEmpty()) {
filters.clear();
filters.addAll(parsedFilters);
}
if (!parsedGlue.isEmpty()) {
glue.clear();
glue.addAll(parsedGlue);
}
}
private void addPluginName(final String pluginString) {
pluginNames.add(pluginString);
}
public List getGlue() {
return glue;
}
public Boolean isStrict() {
return strict;
}
public Boolean isDryRun() {
return dryRun;
}
public List getFilters() {
return filters;
}
public Boolean isMonochrome() {
return monochrome;
}
public List getPluginNames() {
return pluginNames;
}
}