25
25
import com .github .fonimus .ssh .shell .interactive .KeyBinding ;
26
26
import com .github .fonimus .ssh .shell .providers .ExtendedFileValueProvider ;
27
27
import lombok .AllArgsConstructor ;
28
+ import lombok .Data ;
29
+ import lombok .NoArgsConstructor ;
28
30
import org .apache .sshd .server .Environment ;
29
31
import org .apache .sshd .server .session .ServerSession ;
30
32
import org .jline .terminal .Size ;
40
42
import org .springframework .shell .CompletionContext ;
41
43
import org .springframework .shell .CompletionProposal ;
42
44
import 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 ;
43
48
import org .springframework .stereotype .Component ;
44
49
45
50
import java .io .File ;
@@ -62,17 +67,58 @@ public class CompleteCommands extends AbstractHealthIndicator {
62
67
* Echo command
63
68
*
64
69
* @param message message to print
70
+ * @param color color for the message
65
71
* @return message
66
72
*/
67
73
@ 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
+ ) {
69
78
if (color != null ) {
70
79
return new AttributedStringBuilder ().append (message ,
71
80
AttributedStyle .DEFAULT .foreground (color .toJlineAttributedStyle ())).toAnsi ();
72
81
}
73
82
return message ;
74
83
}
75
84
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
+
76
122
/**
77
123
* Terminal size command example
78
124
*
@@ -83,6 +129,56 @@ public Size size() {
83
129
return helper .terminalSize ();
84
130
}
85
131
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
+
86
182
/**
87
183
* Progress displays command example
88
184
*
@@ -128,7 +224,7 @@ private void info(File file) {
128
224
* @param delay delay in ms
129
225
*/
130
226
@ 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 ) {
132
228
133
229
KeyBinding binding = KeyBinding .builder ()
134
230
.description ("K binding example" )
@@ -177,16 +273,6 @@ public String welcome() {
177
273
return "Hello, '" + name + "' !" ;
178
274
}
179
275
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
-
190
276
/**
191
277
* Admin only example command
192
278
*
@@ -309,6 +395,16 @@ public void logWithLongDuration() throws InterruptedException {
309
395
protected void doHealthCheck (Health .Builder builder ) {
310
396
builder .up ().withDetail ("a-key" , "a-value" );
311
397
}
398
+
399
+ @ Data
400
+ @ NoArgsConstructor
401
+ @ AllArgsConstructor
402
+ private static class Pojo {
403
+
404
+ private String key1 ;
405
+
406
+ private String key2 ;
407
+ }
312
408
}
313
409
314
410
@ Component
0 commit comments