@@ -21,6 +21,8 @@ import java.util.List;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
|
||||
/**
|
||||
* An example straight from the JCommander documentation.
|
||||
*
|
||||
@@ -31,6 +33,7 @@ public class Args {
|
||||
@Parameter
|
||||
private List<String> parameters = new ArrayList<>();
|
||||
|
||||
@Min(3)
|
||||
@Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
|
||||
private Integer verbose = 1;
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import org.springframework.shell.standard.ShellComponent;
|
||||
import org.springframework.shell.standard.ShellMethod;
|
||||
import org.springframework.shell.standard.ShellOption;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* A class with JCommander commands.
|
||||
*
|
||||
@@ -29,7 +31,7 @@ import org.springframework.shell.standard.ShellOption;
|
||||
public class JCommanderCommands {
|
||||
|
||||
@ShellMethod("Bind parameters to JCommander POJO.")
|
||||
public String jcommander(@ShellOption(optOut = true) Args args) {
|
||||
public String jcommander(@ShellOption(optOut = true) @Valid Args args) {
|
||||
return "You said " + args;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import org.springframework.shell.standard.ShellOption;
|
||||
import org.springframework.shell.standard.ValueProviderSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* Example commands for the Shell 2 Standard resolver.
|
||||
*
|
||||
@@ -44,7 +46,7 @@ public class Commands {
|
||||
}
|
||||
|
||||
@ShellMethod("It's cool.")
|
||||
public String foo(String bar) {
|
||||
public String foo(@Size(min = 2) String bar) {
|
||||
return bar;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user