Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 1621b9a

Browse files
committed
✨ Bump spring boot and shell (and others), add fix on completion
1 parent 164d03a commit 1621b9a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

starter/src/main/java/com/github/fonimus/ssh/shell/commands/ManageSessionsCommand.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@
2020
import com.github.fonimus.ssh.shell.SshShellHelper;
2121
import com.github.fonimus.ssh.shell.SshShellProperties;
2222
import com.github.fonimus.ssh.shell.manage.SshShellSessionManager;
23+
import lombok.AllArgsConstructor;
24+
import lombok.extern.slf4j.Slf4j;
2325
import org.apache.sshd.server.channel.ChannelSession;
2426
import org.apache.sshd.server.session.ServerSession;
2527
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2628
import org.springframework.context.annotation.Lazy;
2729
import org.springframework.shell.Availability;
28-
import org.springframework.shell.standard.ShellCommandGroup;
29-
import org.springframework.shell.standard.ShellMethod;
30-
import org.springframework.shell.standard.ShellMethodAvailability;
31-
import org.springframework.shell.standard.ShellOption;
30+
import org.springframework.shell.CompletionContext;
31+
import org.springframework.shell.CompletionProposal;
32+
import org.springframework.shell.standard.*;
33+
import org.springframework.stereotype.Component;
3234

3335
import java.util.Arrays;
36+
import java.util.List;
3437
import java.util.Map;
38+
import java.util.stream.Collectors;
3539

3640
import static com.github.fonimus.ssh.shell.manage.SshShellSessionManager.sessionUserName;
3741

@@ -80,7 +84,7 @@ public String manageSessionsList() {
8084

8185
@ShellMethod(key = COMMAND_MANAGE_SESSIONS_INFO, value = "Displays session")
8286
@ShellMethodAvailability("manageSessionsInfoAvailability")
83-
public String manageSessionsInfo(@ShellOption(help = "Session identifier") long sessionId) {
87+
public String manageSessionsInfo(@ShellOption(help = "Session identifier", valueProvider = SessionsValuesProvider.class) long sessionId) {
8488
ChannelSession session = sessionManager.getSession(sessionId);
8589
if (session == null) {
8690
return helper.getError("Session [" + sessionId + "] not found");
@@ -90,7 +94,7 @@ public String manageSessionsInfo(@ShellOption(help = "Session identifier") long
9094

9195
@ShellMethod(key = COMMAND_MANAGE_SESSIONS_STOP, value = "Stop session")
9296
@ShellMethodAvailability("manageSessionsStopAvailability")
93-
public String manageSessionsStop(@ShellOption(help = "Session identifier") long sessionId) {
97+
public String manageSessionsStop(@ShellOption(help = "Session identifier", valueProvider = SessionsValuesProvider.class) long sessionId) {
9498
return sessionManager.stopSession(sessionId) ?
9599
helper.getSuccess("Session [" + sessionId + "] stopped") :
96100
helper.getWarning("Unable to stop session [" + sessionId + "], maybe it does not exist");
@@ -119,3 +123,18 @@ private Availability manageSessionsStopAvailability() {
119123
return availability(GROUP, COMMAND_MANAGE_SESSIONS_STOP);
120124
}
121125
}
126+
127+
@Slf4j
128+
@Component
129+
@AllArgsConstructor
130+
class SessionsValuesProvider
131+
implements ValueProvider {
132+
133+
@Lazy
134+
private final SshShellSessionManager sessionManager;
135+
136+
@Override
137+
public List<CompletionProposal> complete(CompletionContext completionContext) {
138+
return sessionManager.listSessions().keySet().stream().map(id -> new CompletionProposal(id.toString())).collect(Collectors.toList());
139+
}
140+
}

starter/src/test/java/com/github/fonimus/ssh/shell/ExtendedShellTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ private static List<Arguments> completeSource() {
141141
// used complete adapter
142142
Arguments.of("cmd --ac ", Arrays.asList("cp1", "cp2")),
143143
// propose only not used options
144-
Arguments.of("cmd --ac cp1 ", Collections.singletonList("--ab"))
144+
Arguments.of("cmd --ac cp1 ", Collections.singletonList("--ab")),
145+
// after pipe, complete with post processors
146+
Arguments.of("cmd --ac cp1 --ab test | ", Collections.singletonList("grep"))
145147
);
146148
}
147149

0 commit comments

Comments
 (0)