forked from phoedos/pmd
Allow positional parameters as equivalent to -d
This commit is contained in:
@@ -6,6 +6,7 @@ package net.sourceforge.pmd.cli.commands.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.cli.commands.mixins.internal.EncodingMixin;
|
||||
@@ -13,6 +14,7 @@ import net.sourceforge.pmd.cli.commands.mixins.internal.EncodingMixin;
|
||||
import picocli.CommandLine.Mixin;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.ParameterException;
|
||||
import picocli.CommandLine.Parameters;
|
||||
|
||||
public abstract class AbstractAnalysisPmdSubcommand extends AbstractPmdSubcommand {
|
||||
|
||||
@@ -24,7 +26,7 @@ public abstract class AbstractAnalysisPmdSubcommand extends AbstractPmdSubcomman
|
||||
+ "Zip and Jar files are also supported, if they are specified directly "
|
||||
+ "(archive files found while exploring a directory are not recursively expanded). "
|
||||
+ "This option can be repeated, and multiple arguments can be provided to a single occurrence of the option. "
|
||||
+ "One of --dir, --file-list or --uri must be provided. ",
|
||||
+ "One of --dir, --file-list or --uri must be provided.",
|
||||
arity = "1..*", split = ",")
|
||||
protected List<Path> inputPaths;
|
||||
|
||||
@@ -44,6 +46,16 @@ public abstract class AbstractAnalysisPmdSubcommand extends AbstractPmdSubcomman
|
||||
+ "Disable this option with '--no-fail-on-violation' to exit with 0 instead and just write the report.",
|
||||
defaultValue = "true", negatable = true)
|
||||
protected boolean failOnViolation;
|
||||
|
||||
@Parameters(arity = "*", description = "Path to a source file, or directory containing source files to analyze. "
|
||||
+ "Equivalent to using --dir.")
|
||||
public void setInputPaths(final List<Path> inputPaths) {
|
||||
if (this.inputPaths == null) {
|
||||
this.inputPaths = new ArrayList<>();
|
||||
}
|
||||
|
||||
this.inputPaths.addAll(inputPaths);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void validate() throws ParameterException {
|
||||
|
@@ -43,10 +43,10 @@ class CpdCommandTest extends BaseCommandTest<CpdCommand> {
|
||||
|
||||
@Test
|
||||
void testNoPositionalParametersAllowed() {
|
||||
assertError(
|
||||
// vvvv
|
||||
"-d", "a", "--", "-d", "b"
|
||||
final CpdCommand cmd = setupAndParse(
|
||||
"-d", "a", "--", "b"
|
||||
);
|
||||
assertMultipleDirs(cmd);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,8 +68,8 @@ class CpdCommandTest extends BaseCommandTest<CpdCommand> {
|
||||
protected void addStandardParams(final List<String> argList) {
|
||||
// If no minimum tokens provided, set default value
|
||||
if (!argList.contains("--minimum-tokens")) {
|
||||
argList.add("--minimum-tokens");
|
||||
argList.add("100");
|
||||
argList.add(0, "--minimum-tokens");
|
||||
argList.add(1, "100");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -52,10 +52,10 @@ class PmdCommandTest extends BaseCommandTest<PmdCommand> {
|
||||
|
||||
@Test
|
||||
void testNoPositionalParametersAllowed() {
|
||||
assertError(
|
||||
// vvvv
|
||||
"-R", "x.xml", "-d", "a", "--", "-d", "b"
|
||||
final PmdCommand cmd = setupAndParse(
|
||||
"-R", "x.xml", "-R", "y.xml", "-d", "a", "--", "b"
|
||||
);
|
||||
assertMultipleDirsAndRulesets(cmd);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,8 +83,8 @@ class PmdCommandTest extends BaseCommandTest<PmdCommand> {
|
||||
protected void addStandardParams(final List<String> argList) {
|
||||
// If no language provided, set dummy latest
|
||||
if (!argList.contains("--use-version")) {
|
||||
argList.add("--use-version");
|
||||
argList.add("dummy-1.0");
|
||||
argList.add(0, "--use-version");
|
||||
argList.add(1, "dummy-1.0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user