20
20
import com .github .fonimus .ssh .shell .SshShellHelper ;
21
21
import com .github .fonimus .ssh .shell .SshShellProperties ;
22
22
import com .github .fonimus .ssh .shell .manage .SshShellSessionManager ;
23
+ import lombok .AllArgsConstructor ;
24
+ import lombok .extern .slf4j .Slf4j ;
23
25
import org .apache .sshd .server .channel .ChannelSession ;
24
26
import org .apache .sshd .server .session .ServerSession ;
25
27
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
26
28
import org .springframework .context .annotation .Lazy ;
27
29
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 ;
32
34
33
35
import java .util .Arrays ;
36
+ import java .util .List ;
34
37
import java .util .Map ;
38
+ import java .util .stream .Collectors ;
35
39
36
40
import static com .github .fonimus .ssh .shell .manage .SshShellSessionManager .sessionUserName ;
37
41
@@ -80,7 +84,7 @@ public String manageSessionsList() {
80
84
81
85
@ ShellMethod (key = COMMAND_MANAGE_SESSIONS_INFO , value = "Displays session" )
82
86
@ 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 ) {
84
88
ChannelSession session = sessionManager .getSession (sessionId );
85
89
if (session == null ) {
86
90
return helper .getError ("Session [" + sessionId + "] not found" );
@@ -90,7 +94,7 @@ public String manageSessionsInfo(@ShellOption(help = "Session identifier") long
90
94
91
95
@ ShellMethod (key = COMMAND_MANAGE_SESSIONS_STOP , value = "Stop session" )
92
96
@ 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 ) {
94
98
return sessionManager .stopSession (sessionId ) ?
95
99
helper .getSuccess ("Session [" + sessionId + "] stopped" ) :
96
100
helper .getWarning ("Unable to stop session [" + sessionId + "], maybe it does not exist" );
@@ -119,3 +123,18 @@ private Availability manageSessionsStopAvailability() {
119
123
return availability (GROUP , COMMAND_MANAGE_SESSIONS_STOP );
120
124
}
121
125
}
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
+ }
0 commit comments