Process given values is a parser

- Modify CommandParser to convert given option value if its type is defined
- This change makes option default value to behave same as given value
  what comes for the actual value in a CommandContext.
- Fixes #548
This commit is contained in:
Janne Valkealahti
2022-10-14 06:33:44 +01:00
parent df45b625c7
commit 3fe26025cd
3 changed files with 45 additions and 3 deletions

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.shell.samples.e2e;
import java.io.PrintWriter;
import org.springframework.context.annotation.Bean;
import org.springframework.shell.command.CommandRegistration;
import org.springframework.shell.standard.ShellComponent;
@@ -48,7 +50,14 @@ public class OptionTypeCommands extends BaseE2ECommands {
.label("MYLABEL")
.and()
.withTarget()
.consumer(ctx -> {})
.consumer(ctx -> {
PrintWriter writer = ctx.getTerminal().writer();
if (ctx.hasMappedOption("arg3")) {
int v = ctx.getOptionValue("arg3");
writer.append("arg3=" + Integer.toString(v) + "\n");
}
writer.flush();
})
.and()
.build();
}