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