1====== Tests of CLI Plugin ======
2
3This page provides a set of test cases for the [[plugins:cli|CLI Plugin]] and also serves as an example of its use.
4
5===== Basic Shell Script =====
6
7This shows that
8  * basic ''%%<cli>%%'' is perfect for unix command line,
9  * ''%%<cli>%%'' can nest,
10  * ''%%<cli type=dos>%%'' works just fine with MS command box.
11
12Wiki text:
13  <cli>
14  user@host:~/somedir $ ls # List current directory
15  conf  plugin.info.txt  README	  syntax.php
16  lang  style.css
17  user@host:~/somedir $ wc info.txt # count words in info.txt
18    7  20 204 info.txt
19  user@host:~/somedir $ ls \
20  > -l # Here we ask a long listing (-l)
21  total 40
22  drwxr-xr-x 2 user user  4096 Dec 27 18:48 conf
23  drwxr-xr-x 4 user user  4096 Dec 22 22:10 lang
24  -rw-rw-rw- 1 user user   204 Dec 22 22:04 plugin.info.txt
25  -rw-rw-rw- 1 user user  1220 Dec 27 18:45 README
26  -rw-r--r-- 1 user user   184 Dec 28 02:13 style.css
27  -rw-rw-rw- 1 user user 18822 Dec 28 06:11 syntax.php
28  user@host:~/somedir $ dosemu
29  <cli type=dos>
30  (C) Copyright 1995-2006 Pasquale J. Villani and The FreeDOS Project.
31  D: = LINUX\FS/HOME/USER attrib = READ/WRITE
32  E: = LINUX\FS/MEDIA/CDROM CDROM:1 attrib = READ ONLY
33  "Welcome to dosemu 1.4.0.8!"
34  C:\>dir
35   Volume in drive C is mu/drives/c
36   Directory of C:\
37
38  TMP                  <DIR>  12-28-17  6:29a
39  CONFIG   SYS           346  06-22-15  1:17a
40  AUTOEXEC BAT           556  06-22-15  1:17a
41           2 file(s)            902 bytes
42           1 dir(s)   2,147,450,880 bytes free
43  C:\>echo pouet
44  pouet
45  C:\>rem This is a remark and does nothing
46  C:\>echo But this rem is not a remark.
47  But this rem is not a remark.
48  C:\>exit
49  </cli>
50  user@host:~/somedir $ echo Ah. Back to normal again
51  Ah. Back to normal again
52  user@host:~/somedir $
53  </cli>
54
55Rendered result :
56
57<cli>
58user@host:~/somedir $ ls # List current directory
59conf  plugin.info.txt  README	  syntax.php
60lang  style.css
61user@host:~/somedir $ wc info.txt # count words in info.txt
62  7  20 204 info.txt
63user@host:~/somedir $ ls \
64> -l # Here we ask a long listing (-l)
65total 40
66drwxr-xr-x 2 user user  4096 Dec 27 18:48 conf
67drwxr-xr-x 4 user user  4096 Dec 22 22:10 lang
68-rw-rw-rw- 1 user user   204 Dec 22 22:04 plugin.info.txt
69-rw-rw-rw- 1 user user  1220 Dec 27 18:45 README
70-rw-r--r-- 1 user user   184 Dec 28 02:13 style.css
71-rw-rw-rw- 1 user user 18822 Dec 28 06:11 syntax.php
72user@host:~/somedir $ dosemu
73<cli type=dos>
74(C) Copyright 1995-2006 Pasquale J. Villani and The FreeDOS Project.
75D: = LINUX\FS/HOME/USER attrib = READ/WRITE
76E: = LINUX\FS/MEDIA/CDROM CDROM:1 attrib = READ ONLY
77"Welcome to dosemu 1.4.0.8!"
78C:\>dir
79 Volume in drive C is mu/drives/c
80 Directory of C:\
81
82TMP                  <DIR>  12-28-17  6:29a
83CONFIG   SYS           346  06-22-15  1:17a
84AUTOEXEC BAT           556  06-22-15  1:17a
85         2 file(s)            902 bytes
86         1 dir(s)   2,147,450,880 bytes free
87C:\>echo pouet
88pouet
89C:\>rem This is a remark and does nothing
90C:\>echo But this rem is not a remark.
91But this rem is not a remark.
92C:\>exit
93</cli>
94user@host:~/somedir $ echo Ah. Back to normal again
95Ah. Back to normal again
96user@host:~/somedir $
97</cli>
98
99
100===== Ruby irb =====
101
102Simple minded implementation will not work for results as end of prompt is same as results marker!
103But named type ''irb'' can handle ruby quite well.
104<code>
105<cli t=irb>
106irb(main):001:0> 2+2
107=> 4
108irb(main):002:0>
109irb(main):003:0> 2 + # This is a comment
110irb(main):004:0* 40
111=> 42
112irb(main):005:0>
113</cli>
114</code>
115
116<cli t=irb >
117irb(main):001:0> 2+2
118=> 4
119irb(main):002:0>
120irb(main):001:0> 2 + # This is a comment
121irb(main):002:0* 40
122=> 42
123irb(main):003:0>
124</cli>
125
126===== Python =====
127
128<code>
129<cli prompt=">>>">
130ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
131Python 2.5.1 (r251:54863, May  1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on
132win32
133Type "help", "copyright", "credits" or "license" for more information.
134>>> 2+2
1354
136>>>
137</cli>
138</code>
139
140
141<cli prompt=">>>">
142ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
143Python 2.5.1 (r251:54863, May  1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on
144win32
145Type "help", "copyright", "credits" or "license" for more information.
146>>> 2+2
1474
148>>>
149</cli>
150
151
152
153
154===== Corner Cases =====
155
156  * The following codes don't display right
157<code>
158<cli prompt="#">
159# rpm -ivh darcs-1.0.9-3.fc6.i386.rpm
160Preparing...                ########################################### [100%]
161   1:darcs                  ########################################### [100%]
162</cli>
163</code>
164
165<cli prompt="#">
166# rpm -ivh darcs-1.0.9-3.fc6.i386.rpm
167Preparing...                ########################################### [100%]
168   1:darcs                  ########################################### [100%]
169</cli>
170
171Not sure to do about this as download progress marker uses same character as prompt!
172
173  * CLI shouldn't silently eat intentional blank lines:
174
175
176End of original demo
177-----------------------------------------------
178
179===== Other examples =====
180
181==== blank lines ====
182
183intentional blank lines are preserved
184
185<cli prompt="$" comment="#">
186user@host:~/somedir $ ls # List current directory
187conf      lang         README        screen,gif  ui
188info.txt  manager.dat  renderer.php  syntax.php
189
190
191user@host:~/somedir $ # Yes the 2 blank lines above are intentional.
192</cli>
193<code>
194<cli prompt="$" comment="#">
195user@host:~/somedir $ ls # List current directory
196conf      lang         README        screen,gif  ui
197info.txt  manager.dat  renderer.php  syntax.php
198
199
200user@host:~/somedir $ # Yes the 2 blank lines above are intentional.
201</cli>
202</code>
203
204==== nesting ====
205
206There are 2 %%<cli>%% nested here :
207
208<cli prompt="$" cont='>>>'>
209user@host:~/somedir $ ls # List current directory | tee /tmp/foo < /dev/null
210conf      lang         README        screen,gif  ui
211info.txt  manager.dat  renderer.ph   syntax.php  z
212$ \
213>>> # see next line
214>>> :<<YOP
215kkk
216
217
218YOP
219
220>>> This is not a continuation line.
221user@host:~/somedir $ dosemu # two blank lines above.
222<cli prompt="/^[A-Za-z]:.*> /" continue="/^  /">
223c:\> dir
224directory of C:\.
225.             <DIR>           16-12-2017   9:03
226..            <DIR>           16-12-2017   8:57
227caramba  txt             1023 16-12-2017  14:23
228    1 File(s)            1023 Bytes.
229    2 Dir(s)      262,111,744 Bytes free.
230C:\docs> exit
231</cli>
232user@host:~/somedir $ echo 'pouet   &   repouet'
233pouet   &   repouet
234user@host:~/somedir $
235</cli>
236
237<code>
238<cli prompt="$" cont='>>>'>
239user@host:~/somedir $ ls # List current directory | tee /tmp/foo < /dev/null
240conf      lang         README        screen,gif  ui
241info.txt  manager.dat  renderer.ph   syntax.php  z
242$ \
243>>> # see next line
244>>> :<<YOP
245kkk
246
247
248YOP
249
250>>> This is not a continuation line.
251user@host:~/somedir $ dosemu # two blank lines above.
252<cli prompt="/^[A-Za-z]:.*> /" continue="/^  /">
253c:\> dir
254directory of C:\.
255.             <DIR>           16-12-2017   9:03
256..            <DIR>           16-12-2017   8:57
257caramba  txt             1023 16-12-2017  14:23
258    1 File(s)            1023 Bytes.
259    2 Dir(s)      262,111,744 Bytes free.
260C:\docs> exit
261</cli>
262user@host:~/somedir $ echo 'pouet   &   repouet'
263pouet   &   repouet
264user@host:~/somedir $
265</cli>
266</code>
267
268---------------------
269This could also have been done in one %%<cli>%% provided you are a master at regexp
270
271<cli prompt='/^([a-zA-Z]:.*?>)|.*?[$] /' cont='>>>'>
272user@host:~/somedir $ ls # List current directory | tee /tmp/foo < /dev/null
273conf      lang         README        screen,gif  ui
274info.txt  manager.dat  renderer.ph   syntax.php  z
275$ \
276>>> # see next line
277>>> :<<YOP
278kkk
279
280
281YOP
282
283>>> This is not a continuation line.
284user@host:~/somedir $ dosemu # two blank lines above.
285c:\> cd docs
286c:\docs> dir
287directory of C:\docs.
288.             <DIR>           16-12-2017   9:03
289..            <DIR>           16-12-2017   8:57
290caramba  txt             1023 16-12-2017  14:23
291    1 File(s)            1023 Bytes.
292    2 Dir(s)      262,111,744 Bytes free.
293C:\docs> exit
294user@host:~/somedir $ echo 'pouet   &   repouet'
295pouet   &   repouet
296user@host:~/somedir $
297</cli>
298
299<code>
300<cli prompt='/^([a-zA-Z]:.*?> )|.*?[$] /' cont='>>>'>
301user@host:~/somedir $ ls # List current directory | tee /tmp/foo < /dev/null
302conf      lang         README        screen,gif  ui
303info.txt  manager.dat  renderer.ph   syntax.php  z
304$ \
305>>> # see next line
306>>> :<<YOP
307kkk
308
309
310YOP
311
312>>> This is not a continuation line.
313user@host:~/somedir $ dosemu # two blank lines above.
314c:\> cd docs
315c:\docs> dir
316directory of C:\docs.
317.             <DIR>           16-12-2017   9:03
318..            <DIR>           16-12-2017   8:57
319caramba  txt             1023 16-12-2017  14:23
320    1 File(s)            1023 Bytes.
321    2 Dir(s)      262,111,744 Bytes free.
322C:\docs> exit
323user@host:~/somedir $ echo 'pouet   &   repouet'
324pouet   &   repouet
325user@host:~/somedir $
326</cli>
327</code>
328
329===== prompt without space =====
330
331Some command line do not use a space after their prompt. For example, cmd.exe or the command line interface of switch. In this case, use the preset nospace type
332
333<code>
334<cli t=nospace cont=Password:>
335user@myserver:~$ minicom
336
337
338Welcome to minicom 2.7
339
340OPTIONS: I18n
341Compiled on Apr 22 2017, 09:14:19.
342Port /dev/ttyS1
343
344Press CTRL-A Z for help on special keys
345
346
347console>enable
348Password:********************
349console#config
350console(config)#crypto key generate dsa
351console(config)#crypto key generate rsa
352console(config)#ip ssh server
353console(config)#aaa authentication login networkList line
354console(config)#aaa authentication enable networkList line
355console(config)#line ssh
356console(config-line)#login authentication networkList
357console(config-line)#enable authentication networkList
358console(config-line)#password Sup3rPassW0RD
359console(config-line)#exit
360console(config)#exit
361console#copy running-config startup-config
362</cli>
363</code>
364
365<cli t=nospace cont=Password:>
366user@myserver:~$ minicom
367
368
369Welcome to minicom 2.7
370
371OPTIONS: I18n
372Compiled on Apr 22 2017, 09:14:19.
373Port /dev/ttyS1
374
375Press CTRL-A Z for help on special keys
376
377
378console>enable
379Password:********************
380console#config
381console(config)#crypto key generate dsa
382console(config)#crypto key generate rsa
383console(config)#ip ssh server
384console(config)#aaa authentication login networkList line
385console(config)#aaa authentication enable networkList line
386console(config)#line ssh
387console(config-line)#login authentication networkList
388console(config-line)#enable authentication networkList
389console(config-line)#password Sup3rPassW0RD
390console(config-line)#exit
391console(config)#exit
392console#copy running-config startup-config
393</cli>
394