1414 */
1515package org .apache .geode .management .internal .cli ;
1616
17+ import org .apache .commons .lang .StringUtils ;
18+ import org .apache .geode .management .cli .CliMetaData ;
19+ import org .apache .geode .management .internal .cli .shell .GfshExecutionStrategy ;
20+ import org .apache .geode .management .internal .cli .shell .OperationInvoker ;
21+ import org .springframework .shell .core .annotation .CliCommand ;
22+ import org .springframework .shell .core .annotation .CliOption ;
23+ import org .springframework .shell .event .ParseResult ;
24+
25+ import java .lang .annotation .Annotation ;
1726import java .lang .reflect .Method ;
1827import java .util .Collections ;
1928import java .util .HashMap ;
2029import java .util .Map ;
2130
22- import org .springframework .shell .event .ParseResult ;
23-
24- import org .apache .geode .management .cli .CliMetaData ;
25- import org .apache .geode .management .internal .cli .shell .GfshExecutionStrategy ;
26- import org .apache .geode .management .internal .cli .shell .OperationInvoker ;
27-
2831/**
2932 * Immutable representation of the outcome of parsing a given shell line. * Extends
3033 * {@link ParseResult} to add a field to specify the command string that was input by the user.
4144public class GfshParseResult extends ParseResult {
4245 private String userInput ;
4346 private String commandName ;
44- private Map <String , String > paramValueStringMap ;
47+ private Map <String , String > paramValueStringMap = new HashMap <>() ;
4548
4649 /**
4750 * Creates a GfshParseResult instance to represent parsing outcome.
@@ -52,12 +55,34 @@ public class GfshParseResult extends ParseResult {
5255 * @param userInput user specified commands string
5356 */
5457 protected GfshParseResult (final Method method , final Object instance , final Object [] arguments ,
55- final String userInput , final String commandName ,
56- final Map <String , String > parametersAsString ) {
58+ final String userInput ) {
5759 super (method , instance , arguments );
58- this .userInput = userInput ;
59- this .commandName = commandName ;
60- this .paramValueStringMap = new HashMap <String , String >(parametersAsString );
60+ this .userInput = userInput .trim ();
61+
62+ CliCommand cliCommand = method .getAnnotation (CliCommand .class );
63+ commandName = cliCommand .value ()[0 ];
64+
65+ Annotation [][] parameterAnnotations = method .getParameterAnnotations ();
66+ if (arguments == null ) {
67+ return ;
68+ }
69+
70+ for (int i = 0 ; i < arguments .length ; i ++) {
71+ Object argument = arguments [i ];
72+ if (argument == null ) {
73+ continue ;
74+ }
75+
76+ CliOption cliOption = getCliOption (parameterAnnotations , i );
77+
78+ String argumentAsString ;
79+ if (argument instanceof Object []) {
80+ argumentAsString = StringUtils .join ((Object []) argument , "," );
81+ } else {
82+ argumentAsString = argument .toString ();
83+ }
84+ paramValueStringMap .put (cliOption .key ()[0 ], argumentAsString );
85+ }
6186 }
6287
6388 /**
@@ -67,26 +92,24 @@ public String getUserInput() {
6792 return userInput ;
6893 }
6994
70-
7195 /**
7296 * @return the unmodifiable paramValueStringMap
7397 */
7498 public Map <String , String > getParamValueStrings () {
7599 return Collections .unmodifiableMap (paramValueStringMap );
76100 }
77101
78- @ Override
79- public String toString () {
80- StringBuilder builder = new StringBuilder ();
81- builder .append (GfshParseResult .class .getSimpleName ());
82- builder .append (" [method=" ).append (getMethod ());
83- builder .append (", instance=" ).append (getInstance ());
84- builder .append (", arguments=" ).append (CliUtil .arrayToString (getArguments ()));
85- builder .append ("]" );
86- return builder .toString ();
87- }
88-
89102 public String getCommandName () {
90103 return commandName ;
91104 }
105+
106+ private CliOption getCliOption (Annotation [][] parameterAnnotations , int index ) {
107+ Annotation [] annotations = parameterAnnotations [index ];
108+ for (Annotation annotation : annotations ) {
109+ if (annotation instanceof CliOption ) {
110+ return (CliOption ) annotation ;
111+ }
112+ }
113+ return null ;
114+ }
92115}
0 commit comments