Use CommandContext as method parameter

- With annotation(@Command) model it's now possible to just
  add CommandContext and it will get resolved and doesn't
  cause it to appear as an option.
- Fixes #779
This commit is contained in:
Janne Valkealahti
2024-01-24 15:38:22 +00:00
parent ef3b6e1f3d
commit 9830fafe1a
6 changed files with 137 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 the original author or authors.
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,9 @@ import org.jline.terminal.Terminal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.shell.command.CommandContext;
import org.springframework.shell.command.CommandRegistration;
import org.springframework.shell.command.annotation.Command;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.stereotype.Component;
@@ -44,6 +46,21 @@ public class WriteCommands {
}
}
@Command(command = BaseE2ECommands.ANNO, group = BaseE2ECommands.GROUP)
public static class Annotation extends BaseE2ECommands {
@Command(command = "write-terminalwriter")
public void writeTerminalWriter(CommandContext ctx) {
ctx.getTerminal().writer().println("hi");
ctx.getTerminal().writer().flush();
}
@Command(command = "write-systemout")
public void writeSystemOut() {
System.out.println("hi");
}
}
@Component
public static class Registration extends BaseE2ECommands {