Skip to content

Commit

Permalink
Allow disabling the parser validation.
Browse files Browse the repository at this point in the history
Signed-off-by: Clement Escoffier <clement.escoffier@gmail.com>
  • Loading branch information
cescoffier committed Sep 15, 2015
1 parent ffbfdfe commit fc50f24
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/main/java/io/vertx/core/cli/CLI.java
Expand Up @@ -76,6 +76,15 @@ static CLI create(Class<?> clazz) {
*/
CommandLine parse(List<String> arguments);

/**
* Parses the user command line interface and create a new {@link CommandLine} containing extracting values.
*
* @param arguments the arguments
* @param validate enable / disable parsing validation
* @return the creates command line
*/
CommandLine parse(List<String> arguments, boolean validate);

/**
* @return the CLI name.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/vertx/core/cli/impl/DefaultCLI.java
Expand Up @@ -52,6 +52,18 @@ public CommandLine parse(List<String> arguments) {
return new DefaultParser().parse(this, arguments);
}

/**
* Parses the user command line interface and create a new {@link CommandLine} containing extracting values.
*
* @param arguments the arguments
* @param validate enable / disable parsing validation
* @return the creates command line
*/
@Override
public CommandLine parse(List<String> arguments, boolean validate) {
return new DefaultParser().parse(this, arguments, validate);
}

@Override
public String getName() {
return name;
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/io/vertx/core/cli/impl/DefaultParser.java
Expand Up @@ -79,6 +79,11 @@ static String stripLeadingAndTrailingQuotes(String str) {

public CommandLine parse(CLI cli, List<String> cla)
throws CLIException {
return parse(cli, cla, true);
}

public CommandLine parse(CLI cli, List<String> cla, boolean validate)
throws CLIException {
commandLine = (DefaultCommandLine) CommandLine.create(cli);
current = null;
skipParsing = false;
Expand All @@ -98,14 +103,17 @@ public CommandLine parse(CLI cli, List<String> cla)
}
}

// check the values of the last option
checkRequiredValues();

// check that all required options has a value
checkRequiredOptions();
if (validate) {
// check the values of the last option
checkRequiredValues();

// check that all required options has a value
checkRequiredOptions();

// Call global validation.
validate();
// Call global validation.
validate();
}

return commandLine;
}
Expand Down

0 comments on commit fc50f24

Please sign in to comment.