2525import com .github .fonimus .ssh .shell .interactive .KeyBinding ;
2626import com .github .fonimus .ssh .shell .providers .ExtendedFileValueProvider ;
2727import lombok .AllArgsConstructor ;
28+ import lombok .Data ;
29+ import lombok .NoArgsConstructor ;
2830import org .apache .sshd .server .Environment ;
2931import org .apache .sshd .server .session .ServerSession ;
3032import org .jline .terminal .Size ;
4042import org .springframework .shell .CompletionContext ;
4143import org .springframework .shell .CompletionProposal ;
4244import org .springframework .shell .standard .*;
45+ import org .springframework .shell .table .BorderStyle ;
46+ import org .springframework .shell .table .SimpleHorizontalAligner ;
47+ import org .springframework .shell .table .SimpleVerticalAligner ;
4348import org .springframework .stereotype .Component ;
4449
4550import java .io .File ;
@@ -62,17 +67,58 @@ public class CompleteCommands extends AbstractHealthIndicator {
6267 * Echo command
6368 *
6469 * @param message message to print
70+ * @param color color for the message
6571 * @return message
6672 */
6773 @ ShellMethod ("Echo command" )
68- public String echo (String message , @ ShellOption (defaultValue = ShellOption .NULL , valueProvider = EnumValueProvider .class ) PromptColor color ) {
74+ public String echo (
75+ @ ShellOption (valueProvider = CustomValuesProvider .class ) String message ,
76+ @ ShellOption (defaultValue = ShellOption .NULL , valueProvider = EnumValueProvider .class ) PromptColor color
77+ ) {
6978 if (color != null ) {
7079 return new AttributedStringBuilder ().append (message ,
7180 AttributedStyle .DEFAULT .foreground (color .toJlineAttributedStyle ())).toAnsi ();
7281 }
7382 return message ;
7483 }
7584
85+ /**
86+ * Wait for some time
87+ *
88+ * @param waitInMillis wait time
89+ * @return message
90+ */
91+ @ ShellMethod (key = "wait" , value = "Wait command" )
92+ public String waitCmd (long waitInMillis ) {
93+ try {
94+ Thread .sleep (waitInMillis );
95+ } catch (InterruptedException e ) {
96+ LOGGER .warn ("Got interrupted" );
97+ }
98+ return "Waited " + waitInMillis + " milliseconds" ;
99+ }
100+
101+ /**
102+ * Pojo command
103+ * <p>Try the post processors like pretty, grep with it</p>
104+ *
105+ * @return pojo
106+ */
107+ @ ShellMethod ("Pojo command" )
108+ public Pojo pojo () {
109+ return new Pojo ("value1" , "value2" );
110+ }
111+
112+ /**
113+ * Confirmation example command
114+ *
115+ * @return welcome message
116+ */
117+ @ ShellMethod ("Confirmation command" )
118+ public String conf () {
119+ return helper .confirm ("Are you sure ?" ) ? "Great ! Let's do it !" : "Such a shame ..." ;
120+ }
121+
76122 /**
77123 * Terminal size command example
78124 *
@@ -83,6 +129,56 @@ public Size size() {
83129 return helper .terminalSize ();
84130 }
85131
132+ /**
133+ * Simple table example command
134+ *
135+ * @return principal
136+ */
137+ @ ShellMethod ("Simple table command" )
138+ public String tableSimple () {
139+ return helper .renderTable (SimpleTable .builder ()
140+ .column ("col1" )
141+ .column ("col2" )
142+ .column ("col3" )
143+ .column ("col4" )
144+ .line (Arrays .asList ("line1 col1" , "line1 col2" , "line1 col3" , "line1 col4" ))
145+ .line (Arrays .asList ("line2 col1" , "line2 col2" , "line2 col3" , "line2 col4" ))
146+ .line (Arrays .asList ("line3 col1" , "line3 col2" , "line3 col3" , "line3 col4" ))
147+ .line (Arrays .asList ("line4 col1" , "line4 col2" , "line4 col3" , "line4 col4" ))
148+ .line (Arrays .asList ("line5 col1" , "line5 col2" , "line5 col3" , "line5 col4" ))
149+ .line (Arrays .asList ("line6 col1" , "line6 col2" , "line6 col3" , "line6 col4" ))
150+ .build ());
151+ }
152+
153+ /**
154+ * Complex table example command
155+ *
156+ * @return principal
157+ */
158+ @ ShellMethod ("Complex table command" )
159+ public String tableComplex () {
160+ return helper .renderTable (SimpleTable .builder ()
161+ .column ("col1" )
162+ .column ("col2" )
163+ .column ("col3" )
164+ .column ("col4" )
165+ .line (Arrays .asList ("line1 col1" , "line1 col2" , "line1 col3" , "line1 col4" ))
166+ .line (Arrays .asList ("line2 col1" , "line2 col2" , "line2 col3" , "line2 col4" ))
167+ .line (Arrays .asList ("line3 col1" , "line3 col2" , "line3 col3" , "line3 col4" ))
168+ .line (Arrays .asList ("line4 col1" , "line4 col2" , "line4 col3" , "line4 col4" ))
169+ .line (Arrays .asList ("line5 col1" , "line5 col2" , "line5 col3" , "line5 col4" ))
170+ .line (Arrays .asList ("line6 col1" , "line6 col2" , "line6 col3" , "line6 col4" ))
171+ .headerAligner (SimpleHorizontalAligner .right )
172+ .lineAligner (SimpleHorizontalAligner .left )
173+ .lineAligner (SimpleVerticalAligner .bottom )
174+ .useFullBorder (false )
175+ .borderStyle (BorderStyle .fancy_heavy_double_dash )
176+ .tableBuilderListener (tableBuilder -> {
177+ tableBuilder .addInnerBorder (BorderStyle .fancy_light_double_dash );
178+ tableBuilder .addOutlineBorder (BorderStyle .fancy_double );
179+ }).build ());
180+ }
181+
86182 /**
87183 * Progress displays command example
88184 *
@@ -128,7 +224,7 @@ private void info(File file) {
128224 * @param delay delay in ms
129225 */
130226 @ ShellMethod ("Interactive command" )
131- public void interactive (boolean fullscreen , @ ShellOption (defaultValue = "3000" ) long delay ) {
227+ public void interactive (@ ShellOption ( defaultValue = "false" ) boolean fullscreen , @ ShellOption (defaultValue = "3000" ) long delay ) {
132228
133229 KeyBinding binding = KeyBinding .builder ()
134230 .description ("K binding example" )
@@ -177,16 +273,6 @@ public String welcome() {
177273 return "Hello, '" + name + "' !" ;
178274 }
179275
180- /**
181- * Confirmation example command
182- *
183- * @return welcome message
184- */
185- @ ShellMethod ("Confirmation command" )
186- public String conf () {
187- return helper .confirm ("Are you sure ?" ) ? "Great ! Let's do it !" : "Such a shame ..." ;
188- }
189-
190276 /**
191277 * Admin only example command
192278 *
@@ -309,6 +395,16 @@ public void logWithLongDuration() throws InterruptedException {
309395 protected void doHealthCheck (Health .Builder builder ) {
310396 builder .up ().withDetail ("a-key" , "a-value" );
311397 }
398+
399+ @ Data
400+ @ NoArgsConstructor
401+ @ AllArgsConstructor
402+ private static class Pojo {
403+
404+ private String key1 ;
405+
406+ private String key2 ;
407+ }
312408}
313409
314410@ Component
0 commit comments