Use JCommander resolver in combination with others.
Prepare for implementation of describe()
This commit is contained in:
@@ -21,6 +21,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.beust.jcommander.DynamicParameter;
|
||||
import com.beust.jcommander.JCommander;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.shell2.CompletionContext;
|
||||
import org.springframework.shell2.CompletionProposal;
|
||||
import org.springframework.shell2.ParameterDescription;
|
||||
import org.springframework.shell2.ParameterResolver;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
@@ -40,6 +42,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Eric Bottard
|
||||
*/
|
||||
@Component
|
||||
public class JCommanderParameterResolver implements ParameterResolver {
|
||||
|
||||
private static final Collection<Class<? extends Annotation>> JCOMMANDER_ANNOTATIONS =
|
||||
@@ -80,7 +83,7 @@ public class JCommanderParameterResolver implements ParameterResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterDescription describe(MethodParameter parameter) {
|
||||
public Stream<ParameterDescription> describe(MethodParameter parameter) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,10 @@ import java.util.List;
|
||||
import com.beust.jcommander.Parameter;
|
||||
|
||||
/**
|
||||
* Created by ericbottard on 15/12/15.
|
||||
* A POJO with fields annotated with JCommander annotations.
|
||||
*
|
||||
* @author Eric Bottard
|
||||
* @see MyLordCommands#genesis(FieldCollins)
|
||||
*/
|
||||
public class FieldCollins {
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ import org.springframework.shell2.Utils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Created by ericbottard on 15/12/15.
|
||||
* Unit test for {@link JCommanderParameterResolver}.
|
||||
*
|
||||
* @author Eric Bottard
|
||||
* @author Florent Biville
|
||||
*/
|
||||
public class JCommanderParameterResolverTest {
|
||||
|
||||
|
||||
@@ -17,14 +17,22 @@
|
||||
package org.springframework.shell2.jcommander;
|
||||
|
||||
/**
|
||||
* Created by ericbottard on 15/12/15.
|
||||
* An hypothetical command class, with one method using JCommander args, and the other not.
|
||||
*
|
||||
* @author Eric Bottard
|
||||
*/
|
||||
public class MyLordCommands {
|
||||
|
||||
/**
|
||||
* This method should be supported.
|
||||
*/
|
||||
public void genesis(FieldCollins fieldCollins) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not.
|
||||
*/
|
||||
public void apocalypse(String param) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user