File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
main/java/org/springframework/shell/command
test/java/org/springframework/shell/command Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -183,8 +183,10 @@ public boolean supportsParameter(MethodParameter parameter) {
183183 if (parameterName == null ) {
184184 return false ;
185185 }
186+ Class <?> sourceType = paramValues .get (parameterName ) != null ? paramValues .get (parameterName ).getClass ()
187+ : null ;
186188 return paramValues .containsKey (parameterName ) && conversionService
187- .canConvert (paramValues . get ( parameterName ). getClass () , parameter .getParameterType ());
189+ .canConvert (sourceType , parameter .getParameterType ());
188190 }
189191
190192 @ Override
Original file line number Diff line number Diff line change @@ -100,6 +100,26 @@ public void testMethodExecution2() {
100100 assertThat (pojo1 .method1Ctx ).isNotNull ();
101101 }
102102
103+ @ Test
104+ public void testMethodArgWithoutValue () {
105+ CommandRegistration r1 = CommandRegistration .builder ()
106+ .command ("command1" )
107+ .description ("help" )
108+ .withOption ()
109+ .longNames ("arg1" )
110+ .description ("some arg1" )
111+ .position (0 )
112+ .arity (OptionArity .EXACTLY_ONE )
113+ .and ()
114+ .withTarget ()
115+ .method (pojo1 , "method4" )
116+ .and ()
117+ .build ();
118+ execution .evaluate (r1 , new String []{"--arg1" });
119+ assertThat (pojo1 .method4Count ).isEqualTo (1 );
120+ assertThat (pojo1 .method4Arg1 ).isNull ();
121+ }
122+
103123 @ Test
104124 public void testMethodSinglePositionalArgs () {
105125 CommandRegistration r1 = CommandRegistration .builder ()
You can’t perform that action at this time.
0 commit comments