rbcli 0.2.12 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +39 -38
- data/docs-src/content/development/changelog.md +16 -1
- data/docs-src/themes/hugo-theme-learn/CHANGELOG.md +74 -2
- data/docs-src/themes/hugo-theme-learn/README.md +42 -5
- data/docs-src/themes/hugo-theme-learn/exampleSite/config.toml +27 -0
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/basics/_index.zh.md +12 -0
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/basics/configuration/_index.en.md +6 -4
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/basics/configuration/_index.fr.md +7 -5
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/basics/installation/_index.en.md +1 -1
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/cont/markdown.en.md +88 -61
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/cont/pages/_index.fr.md +3 -3
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/cont/syntaxhighlight.en.md +89 -0
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/shortcodes/children/_index.en.md +2 -2
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/shortcodes/notice.en.md +2 -2
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/showcase.en.md +4 -1
- data/docs-src/themes/hugo-theme-learn/exampleSite/content/showcase.fr.md +4 -1
- data/docs-src/themes/hugo-theme-learn/exampleSite/static/fonts/monogramos-webfont.svg +1 -237
- data/docs-src/themes/hugo-theme-learn/exampleSite/static/images/showcase/inteliver_docs.png +0 -0
- data/docs-src/themes/hugo-theme-learn/exampleSite/static/images/showcase/tshark_dev.png +0 -0
- data/docs-src/themes/hugo-theme-learn/i18n/ar.toml +26 -0
- data/docs-src/themes/hugo-theme-learn/i18n/de.toml +26 -0
- data/docs-src/themes/hugo-theme-learn/i18n/hi.toml +26 -0
- data/docs-src/themes/hugo-theme-learn/i18n/ja.toml +26 -0
- data/docs-src/themes/hugo-theme-learn/i18n/ru.toml +26 -0
- data/docs-src/themes/hugo-theme-learn/i18n/zh-cn.toml +26 -0
- data/docs-src/themes/hugo-theme-learn/layouts/_default/list.html +1 -1
- data/docs-src/themes/hugo-theme-learn/layouts/_default/single.html +1 -2
- data/docs-src/themes/hugo-theme-learn/layouts/partials/footer.html +3 -4
- data/docs-src/themes/hugo-theme-learn/layouts/partials/header.html +8 -6
- data/docs-src/themes/hugo-theme-learn/layouts/partials/menu.html +6 -5
- data/docs-src/themes/hugo-theme-learn/layouts/shortcodes/children.html +2 -2
- data/docs-src/themes/hugo-theme-learn/layouts/shortcodes/ref.html +1 -1
- data/docs-src/themes/hugo-theme-learn/layouts/shortcodes/relref.html +1 -1
- data/docs-src/themes/hugo-theme-learn/netlify.toml +1 -2
- data/docs-src/themes/hugo-theme-learn/static/css/theme.css +4 -0
- data/docs-src/themes/hugo-theme-learn/static/fonts/Inconsolata.svg +1 -359
- data/docs-src/themes/hugo-theme-learn/static/fonts/Novecentosanswide-Normal-webfont.svg +1 -1019
- data/docs-src/themes/hugo-theme-learn/static/fonts/Novecentosanswide-UltraLight-webfont.svg +1 -918
- data/docs-src/themes/hugo-theme-learn/static/fonts/Work_Sans_200.svg +1 -332
- data/docs-src/themes/hugo-theme-learn/static/fonts/Work_Sans_300.svg +1 -331
- data/docs-src/themes/hugo-theme-learn/static/fonts/Work_Sans_500.svg +1 -333
- data/docs-src/themes/hugo-theme-learn/static/images/clippy.svg +1 -1
- data/docs-src/themes/hugo-theme-learn/static/js/auto-complete.js +3 -223
- data/docs-src/themes/hugo-theme-learn/static/js/highlight.pack.js +6 -3
- data/docs-src/themes/hugo-theme-learn/static/js/hugo-learn.js +8 -5
- data/docs-src/themes/hugo-theme-learn/static/webfonts/fa-brands-400.svg +1 -1260
- data/docs-src/themes/hugo-theme-learn/static/webfonts/fa-regular-400.svg +1 -471
- data/docs-src/themes/hugo-theme-learn/static/webfonts/fa-solid-900.svg +1 -2763
- data/docs/404.html +8 -8
- data/docs/advanced/automatic_updates/index.html +85 -65
- data/docs/advanced/command_types/index.html +139 -144
- data/docs/advanced/distributed_state_locking/index.html +83 -55
- data/docs/advanced/hooks/index.html +94 -81
- data/docs/advanced/index.html +75 -34
- data/docs/advanced/index.xml +8 -8
- data/docs/advanced/interactive_commands/index.html +90 -66
- data/docs/advanced/logging/index.html +94 -67
- data/docs/advanced/remote_execution/index.html +94 -75
- data/docs/advanced/state_storage/index.html +122 -119
- data/docs/advanced/user_config_files/index.html +94 -71
- data/docs/categories/index.html +82 -30
- data/docs/categories/index.xml +1 -1
- data/docs/css/theme.css +4 -0
- data/docs/development/changelog/index.html +185 -177
- data/docs/development/code_of_conduct/index.html +85 -64
- data/docs/development/contributing/index.html +96 -96
- data/docs/development/index.html +75 -34
- data/docs/development/index.xml +2 -2
- data/docs/development/license/index.html +80 -46
- data/docs/fonts/Inconsolata.svg +1 -359
- data/docs/fonts/Novecentosanswide-Normal-webfont.svg +1 -1019
- data/docs/fonts/Novecentosanswide-UltraLight-webfont.svg +1 -918
- data/docs/fonts/Work_Sans_200.svg +1 -332
- data/docs/fonts/Work_Sans_300.svg +1 -331
- data/docs/fonts/Work_Sans_500.svg +1 -333
- data/docs/images/clippy.svg +1 -1
- data/docs/index.html +112 -61
- data/docs/index.json +24 -24
- data/docs/index.xml +13 -13
- data/docs/js/auto-complete.js +3 -223
- data/docs/js/highlight.pack.js +6 -3
- data/docs/js/hugo-learn.js +8 -5
- data/docs/quick_reference/index.html +126 -159
- data/docs/quick_reference/index.xml +1 -1
- data/docs/sitemap.xml +2 -4
- data/docs/tags/index.html +82 -30
- data/docs/tags/index.xml +1 -1
- data/docs/tutorial/10-getting_started/index.html +87 -66
- data/docs/tutorial/20-project_layout/index.html +126 -116
- data/docs/tutorial/30-your_first_command/index.html +151 -141
- data/docs/tutorial/40-options_parameters_and_arguments/index.html +233 -258
- data/docs/tutorial/50-publishing/index.html +86 -66
- data/docs/tutorial/index.html +75 -34
- data/docs/tutorial/index.xml +4 -4
- data/docs/webfonts/fa-brands-400.svg +1 -1260
- data/docs/webfonts/fa-regular-400.svg +1 -471
- data/docs/webfonts/fa-solid-900.svg +1 -2763
- data/docs/whoami/index.html +76 -46
- data/docs/whoami/index.xml +1 -1
- data/lib/rbcli/configuration/configurate_blocks/me.rb +5 -5
- data/lib/rbcli/util/deprecation_warning.rb +21 -4
- data/lib/rbcli/version.rb +1 -1
- data/rbcli.gemspec +8 -8
- data/skeletons/project/Gemfile +1 -1
- data/skeletons/project/config/general.rb +1 -1
- data/skeletons/project/lib/lib.erb +2 -0
- data/skeletons/project/spec/spec_helper.rb +7 -7
- data/skeletons/project/spec/untitled_spec.rb +6 -6
- data/skeletons/project/untitled.gemspec +28 -26
- metadata +29 -20
- data/docs-src/themes/hugo-theme-learn/static/js/html5shiv-printshiv.min.js +0 -4
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<meta name="generator" content="Hugo 0.
|
|
6
|
+
<meta name="generator" content="Hugo 0.74.3" />
|
|
7
7
|
<meta name="description" content="">
|
|
8
8
|
|
|
9
9
|
|
|
@@ -12,20 +12,21 @@
|
|
|
12
12
|
<title>Options, Parameters, and Arguments :: RBCli Documentation</title>
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
<link href="/rbcli/css/nucleus.css?
|
|
16
|
-
<link href="/rbcli/css/fontawesome-all.min.css?
|
|
17
|
-
<link href="/rbcli/css/hybrid.css?
|
|
18
|
-
<link href="/rbcli/css/featherlight.min.css?
|
|
19
|
-
<link href="/rbcli/css/perfect-scrollbar.min.css?
|
|
20
|
-
<link href="/rbcli/css/auto-complete.css?
|
|
21
|
-
<link href="/rbcli/css/atom-one-dark-reasonable.css?
|
|
22
|
-
<link href="/rbcli/css/theme.css?
|
|
23
|
-
<link href="/rbcli/css/hugo-theme.css?
|
|
15
|
+
<link href="/rbcli/css/nucleus.css?1596148729" rel="stylesheet">
|
|
16
|
+
<link href="/rbcli/css/fontawesome-all.min.css?1596148729" rel="stylesheet">
|
|
17
|
+
<link href="/rbcli/css/hybrid.css?1596148729" rel="stylesheet">
|
|
18
|
+
<link href="/rbcli/css/featherlight.min.css?1596148729" rel="stylesheet">
|
|
19
|
+
<link href="/rbcli/css/perfect-scrollbar.min.css?1596148729" rel="stylesheet">
|
|
20
|
+
<link href="/rbcli/css/auto-complete.css?1596148729" rel="stylesheet">
|
|
21
|
+
<link href="/rbcli/css/atom-one-dark-reasonable.css?1596148729" rel="stylesheet">
|
|
22
|
+
<link href="/rbcli/css/theme.css?1596148729" rel="stylesheet">
|
|
23
|
+
<link href="/rbcli/css/hugo-theme.css?1596148729" rel="stylesheet">
|
|
24
|
+
|
|
25
|
+
<link href="/rbcli/css/theme-blue.css?1596148729" rel="stylesheet">
|
|
24
26
|
|
|
25
|
-
<link href="/rbcli/css/theme-blue.css?1561087612" rel="stylesheet">
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
<script src="/rbcli/js/jquery-3.3.1.min.js?
|
|
29
|
+
<script src="/rbcli/js/jquery-3.3.1.min.js?1596148729"></script>
|
|
29
30
|
|
|
30
31
|
<style>
|
|
31
32
|
:root #header + #content > #left > #rlblock_left{
|
|
@@ -54,14 +55,14 @@
|
|
|
54
55
|
<span data-search-clear=""><i class="fas fa-times"></i></span>
|
|
55
56
|
</div>
|
|
56
57
|
|
|
57
|
-
<script type="text/javascript" src="/rbcli/js/lunr.min.js?
|
|
58
|
-
<script type="text/javascript" src="/rbcli/js/auto-complete.js?
|
|
58
|
+
<script type="text/javascript" src="/rbcli/js/lunr.min.js?1596148729"></script>
|
|
59
|
+
<script type="text/javascript" src="/rbcli/js/auto-complete.js?1596148729"></script>
|
|
59
60
|
<script type="text/javascript">
|
|
60
61
|
|
|
61
62
|
var baseurl = "https:\/\/akhoury6.github.io\/rbcli\/";
|
|
62
63
|
|
|
63
64
|
</script>
|
|
64
|
-
<script type="text/javascript" src="/rbcli/js/search.js?
|
|
65
|
+
<script type="text/javascript" src="/rbcli/js/search.js?1596148729"></script>
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
</div>
|
|
@@ -74,6 +75,8 @@
|
|
|
74
75
|
|
|
75
76
|
|
|
76
77
|
|
|
78
|
+
|
|
79
|
+
|
|
77
80
|
|
|
78
81
|
|
|
79
82
|
|
|
@@ -96,6 +99,8 @@
|
|
|
96
99
|
|
|
97
100
|
|
|
98
101
|
|
|
102
|
+
|
|
103
|
+
|
|
99
104
|
|
|
100
105
|
|
|
101
106
|
|
|
@@ -121,6 +126,8 @@
|
|
|
121
126
|
|
|
122
127
|
|
|
123
128
|
|
|
129
|
+
|
|
130
|
+
|
|
124
131
|
|
|
125
132
|
|
|
126
133
|
|
|
@@ -140,6 +147,8 @@
|
|
|
140
147
|
|
|
141
148
|
|
|
142
149
|
|
|
150
|
+
|
|
151
|
+
|
|
143
152
|
|
|
144
153
|
|
|
145
154
|
|
|
@@ -159,6 +168,8 @@
|
|
|
159
168
|
|
|
160
169
|
|
|
161
170
|
|
|
171
|
+
|
|
172
|
+
|
|
162
173
|
|
|
163
174
|
|
|
164
175
|
|
|
@@ -178,6 +189,8 @@
|
|
|
178
189
|
|
|
179
190
|
|
|
180
191
|
|
|
192
|
+
|
|
193
|
+
|
|
181
194
|
|
|
182
195
|
|
|
183
196
|
|
|
@@ -197,6 +210,8 @@
|
|
|
197
210
|
|
|
198
211
|
|
|
199
212
|
|
|
213
|
+
|
|
214
|
+
|
|
200
215
|
|
|
201
216
|
|
|
202
217
|
|
|
@@ -223,6 +238,8 @@
|
|
|
223
238
|
|
|
224
239
|
|
|
225
240
|
|
|
241
|
+
|
|
242
|
+
|
|
226
243
|
|
|
227
244
|
|
|
228
245
|
|
|
@@ -248,6 +265,8 @@
|
|
|
248
265
|
|
|
249
266
|
|
|
250
267
|
|
|
268
|
+
|
|
269
|
+
|
|
251
270
|
|
|
252
271
|
|
|
253
272
|
|
|
@@ -267,6 +286,8 @@
|
|
|
267
286
|
|
|
268
287
|
|
|
269
288
|
|
|
289
|
+
|
|
290
|
+
|
|
270
291
|
|
|
271
292
|
|
|
272
293
|
|
|
@@ -286,6 +307,8 @@
|
|
|
286
307
|
|
|
287
308
|
|
|
288
309
|
|
|
310
|
+
|
|
311
|
+
|
|
289
312
|
|
|
290
313
|
|
|
291
314
|
|
|
@@ -305,6 +328,8 @@
|
|
|
305
328
|
|
|
306
329
|
|
|
307
330
|
|
|
331
|
+
|
|
332
|
+
|
|
308
333
|
|
|
309
334
|
|
|
310
335
|
|
|
@@ -324,6 +349,8 @@
|
|
|
324
349
|
|
|
325
350
|
|
|
326
351
|
|
|
352
|
+
|
|
353
|
+
|
|
327
354
|
|
|
328
355
|
|
|
329
356
|
|
|
@@ -343,6 +370,8 @@
|
|
|
343
370
|
|
|
344
371
|
|
|
345
372
|
|
|
373
|
+
|
|
374
|
+
|
|
346
375
|
|
|
347
376
|
|
|
348
377
|
|
|
@@ -362,6 +391,8 @@
|
|
|
362
391
|
|
|
363
392
|
|
|
364
393
|
|
|
394
|
+
|
|
395
|
+
|
|
365
396
|
|
|
366
397
|
|
|
367
398
|
|
|
@@ -381,6 +412,8 @@
|
|
|
381
412
|
|
|
382
413
|
|
|
383
414
|
|
|
415
|
+
|
|
416
|
+
|
|
384
417
|
|
|
385
418
|
|
|
386
419
|
|
|
@@ -400,6 +433,8 @@
|
|
|
400
433
|
|
|
401
434
|
|
|
402
435
|
|
|
436
|
+
|
|
437
|
+
|
|
403
438
|
|
|
404
439
|
|
|
405
440
|
|
|
@@ -426,6 +461,8 @@
|
|
|
426
461
|
|
|
427
462
|
|
|
428
463
|
|
|
464
|
+
|
|
465
|
+
|
|
429
466
|
|
|
430
467
|
|
|
431
468
|
|
|
@@ -451,6 +488,8 @@
|
|
|
451
488
|
|
|
452
489
|
|
|
453
490
|
|
|
491
|
+
|
|
492
|
+
|
|
454
493
|
|
|
455
494
|
|
|
456
495
|
|
|
@@ -470,6 +509,8 @@
|
|
|
470
509
|
|
|
471
510
|
|
|
472
511
|
|
|
512
|
+
|
|
513
|
+
|
|
473
514
|
|
|
474
515
|
|
|
475
516
|
|
|
@@ -489,6 +530,8 @@
|
|
|
489
530
|
|
|
490
531
|
|
|
491
532
|
|
|
533
|
+
|
|
534
|
+
|
|
492
535
|
|
|
493
536
|
|
|
494
537
|
|
|
@@ -508,6 +551,8 @@
|
|
|
508
551
|
|
|
509
552
|
|
|
510
553
|
|
|
554
|
+
|
|
555
|
+
|
|
511
556
|
|
|
512
557
|
|
|
513
558
|
|
|
@@ -534,6 +579,8 @@
|
|
|
534
579
|
|
|
535
580
|
|
|
536
581
|
|
|
582
|
+
|
|
583
|
+
|
|
537
584
|
|
|
538
585
|
|
|
539
586
|
|
|
@@ -585,7 +632,6 @@
|
|
|
585
632
|
|
|
586
633
|
|
|
587
634
|
|
|
588
|
-
|
|
589
635
|
<section id="body">
|
|
590
636
|
<div id="overlay"></div>
|
|
591
637
|
<div class="padding highlightable">
|
|
@@ -619,9 +665,9 @@
|
|
|
619
665
|
|
|
620
666
|
<a href='/rbcli/'></a> > <a href='/rbcli/tutorial/'>Tutorial</a> > Options, Parameters, and Arguments
|
|
621
667
|
|
|
622
|
-
|
|
668
|
+
|
|
623
669
|
|
|
624
|
-
|
|
670
|
+
|
|
625
671
|
|
|
626
672
|
|
|
627
673
|
|
|
@@ -631,20 +677,18 @@
|
|
|
631
677
|
<div class="progress">
|
|
632
678
|
<div class="wrapper">
|
|
633
679
|
<nav id="TableOfContents">
|
|
634
|
-
<ul>
|
|
635
|
-
<li>
|
|
636
|
-
<
|
|
637
|
-
<li><a href="#
|
|
638
|
-
<
|
|
639
|
-
<li><a href="#
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
</
|
|
643
|
-
<li><a href="#
|
|
644
|
-
<li><a href="#
|
|
645
|
-
|
|
646
|
-
</ul></li>
|
|
647
|
-
</ul>
|
|
680
|
+
<ul>
|
|
681
|
+
<li><a href="#command-line-structure">Command Line Structure</a></li>
|
|
682
|
+
<li><a href="#options">Options</a></li>
|
|
683
|
+
<li><a href="#parameters">Parameters</a>
|
|
684
|
+
<ul>
|
|
685
|
+
<li><a href="#user-prompting">User Prompting</a></li>
|
|
686
|
+
</ul>
|
|
687
|
+
</li>
|
|
688
|
+
<li><a href="#arguments">Arguments</a></li>
|
|
689
|
+
<li><a href="#simplified-reference-tldr">Simplified Reference (TLDR)</a></li>
|
|
690
|
+
<li><a href="#next-steps">Next Steps</a></li>
|
|
691
|
+
</ul>
|
|
648
692
|
</nav>
|
|
649
693
|
</div>
|
|
650
694
|
</div>
|
|
@@ -668,296 +712,228 @@
|
|
|
668
712
|
|
|
669
713
|
|
|
670
714
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
715
|
<p>If you’re already an experienced coder, you can jump to the last section of this document, the <a href="#simplified-reference-tldr">Simplified Reference (TLDR)</a></p>
|
|
675
|
-
|
|
676
716
|
<h2 id="command-line-structure">Command Line Structure</h2>
|
|
677
|
-
|
|
678
717
|
<p>In the previous section, you saw two parts of the RBCli command line structure - the executable followed by the command. However, RBCli is capable of more complex interaction. The structure is as follows:</p>
|
|
679
|
-
|
|
680
718
|
<pre><code>toolname [options] command [parameters] argument1 argument2...
|
|
681
|
-
</code></pre>
|
|
682
|
-
|
|
683
|
-
<ul>
|
|
719
|
+
</code></pre><ul>
|
|
684
720
|
<li><strong>Options</strong> are command line parameters such as <code>-f</code>, or <code>--force</code>. These are available globally to every command. You can create your own, though several are already built-in and reserved for RBCli:
|
|
685
|
-
|
|
686
721
|
<ul>
|
|
687
722
|
<li><code>--config-file=<filename></code> allows specifying a config file location manually.</li>
|
|
688
723
|
<li><code>--generate-config</code> generates a config file for the user by writing out the defaults to a YAML file. This option will only appear if a config file has been set. The location is configurable, with more on that in the documentation on <a href="/rbcli/advanced/user_config_files/">User Config Files</a>).</li>
|
|
689
724
|
<li><code>-v / --version</code> shows the version.</li>
|
|
690
725
|
<li><code>-h / --help</code> shows the help.</li>
|
|
691
|
-
</ul
|
|
726
|
+
</ul>
|
|
727
|
+
</li>
|
|
692
728
|
<li><strong>Command</strong> represents the subcommands that you will create, such as <code>list</code>, <code>test</code>, or <code>apply</code>.</li>
|
|
693
729
|
<li><strong>Parameters</strong> are the same as options, but only apply to the specific subcommand being executed. In this case only the <code>-h / --help</code> parameter is provided automatically.</li>
|
|
694
730
|
<li><strong>Arguments</strong> are strings that don’t begin with a ‘-’, and are passed to the command’s code as an array. These can be used as subcommands or additional parameters for your command.</li>
|
|
695
731
|
</ul>
|
|
696
|
-
|
|
697
732
|
<p>So a valid command could look something like these:</p>
|
|
698
|
-
|
|
699
|
-
<pre><code class="language-shell">mytool -n load --filename=foo.txt
|
|
733
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">mytool -n load --filename<span style="color:#f92672">=</span>foo.txt
|
|
700
734
|
mytool parse foo.txt
|
|
701
735
|
mytool show -l
|
|
702
|
-
</code></pre>
|
|
703
|
-
|
|
704
|
-
<p>Note that all options and parameters will have both a short and long version of the parameter available for use.</p>
|
|
705
|
-
|
|
736
|
+
</code></pre></div><p>Note that all options and parameters will have both a short and long version of the parameter available for use.</p>
|
|
706
737
|
<p>So let’s take a look at how we define them.</p>
|
|
707
|
-
|
|
708
738
|
<h2 id="options">Options</h2>
|
|
709
|
-
|
|
710
739
|
<p>You can find the options declarations under <code>application/options.rb</code>. You’ll see the example in the code:</p>
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
<
|
|
716
|
-
|
|
717
|
-
<
|
|
718
|
-
</
|
|
719
|
-
|
|
720
|
-
<
|
|
721
|
-
|
|
722
|
-
<
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
if global_opts[:color]
|
|
729
|
-
if File.directory? filename
|
|
730
|
-
outname = outname.light_blue
|
|
731
|
-
elsif File.executable? filename
|
|
732
|
-
outname = outname.light_green
|
|
733
|
-
end
|
|
734
|
-
end
|
|
740
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby">option <span style="color:#e6db74">:name</span>, <span style="color:#e6db74">'Give me your name'</span>, <span style="color:#e6db74">short</span>: <span style="color:#e6db74">'n'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:string</span>, <span style="color:#e6db74">default</span>: <span style="color:#e6db74">'Jack'</span>, <span style="color:#e6db74">required</span>: <span style="color:#66d9ef">false</span>, <span style="color:#e6db74">permitted</span>: <span style="color:#f92672">[</span><span style="color:#e6db74">'Jack'</span>, <span style="color:#e6db74">'Jill'</span><span style="color:#f92672">]</span>
|
|
741
|
+
</code></pre></div><p>This won’t do for our tool, so let’s change it. Remember that these options will be applicable to all of our commands, so lets make it something appropriate:</p>
|
|
742
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby">option <span style="color:#e6db74">:color</span>, <span style="color:#e6db74">'Enable color output'</span>, <span style="color:#e6db74">short</span>: <span style="color:#e6db74">'c'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
743
|
+
</code></pre></div><p>So now, let’s take advantage of this flag in our <code>list</code> command. Let’s change our block to:</p>
|
|
744
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby"> action <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>params, args, global_opts, config<span style="color:#f92672">|</span>
|
|
745
|
+
<span style="color:#66d9ef">Dir</span><span style="color:#f92672">.</span>glob <span style="color:#e6db74">"./*"</span> <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
746
|
+
outname <span style="color:#f92672">=</span> filename<span style="color:#f92672">.</span>split(<span style="color:#e6db74">'/'</span>)<span style="color:#f92672">[</span><span style="color:#ae81ff">1</span><span style="color:#f92672">]</span>
|
|
747
|
+
outname <span style="color:#f92672">+=</span> <span style="color:#e6db74">'/'</span> <span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
748
|
+
|
|
749
|
+
<span style="color:#75715e"># We change the color based on the kind of file shown</span>
|
|
750
|
+
<span style="color:#66d9ef">if</span> global_opts<span style="color:#f92672">[</span><span style="color:#e6db74">:color</span><span style="color:#f92672">]</span>
|
|
751
|
+
<span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
752
|
+
outname <span style="color:#f92672">=</span> outname<span style="color:#f92672">.</span>light_blue
|
|
753
|
+
<span style="color:#66d9ef">elsif</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>executable? filename
|
|
754
|
+
outname <span style="color:#f92672">=</span> outname<span style="color:#f92672">.</span>light_green
|
|
755
|
+
<span style="color:#66d9ef">end</span>
|
|
756
|
+
<span style="color:#66d9ef">end</span>
|
|
735
757
|
|
|
736
758
|
puts outname
|
|
737
|
-
end
|
|
738
|
-
end
|
|
739
|
-
</code></pre>
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
<pre><code class="language-bash">mytool -c list
|
|
744
|
-
</code></pre>
|
|
745
|
-
|
|
746
|
-
<h2 id="parameters">Parameters</h2>
|
|
747
|
-
|
|
759
|
+
<span style="color:#66d9ef">end</span>
|
|
760
|
+
<span style="color:#66d9ef">end</span>
|
|
761
|
+
</code></pre></div><p>Notice how we referenced the value by using <code>global_opts[:color]</code>. It’s that simple. To see it in action, run:</p>
|
|
762
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">mytool -c list
|
|
763
|
+
</code></pre></div><h2 id="parameters">Parameters</h2>
|
|
748
764
|
<p>Parameters work the same way as options, but they are localized to only the selected command. They are declared - as you probably guessed by now - in the command’s class. So let’s add the following lines to our list command within the class declaration:</p>
|
|
749
|
-
|
|
750
|
-
<
|
|
751
|
-
parameter
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
<
|
|
758
|
-
filelist = []
|
|
759
|
-
|
|
760
|
-
# We include dotfiles if specified
|
|
761
|
-
include_dotfiles = (params[:all]) ? File::FNM_DOTMATCH : 0
|
|
765
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby">parameter <span style="color:#e6db74">:sort</span>, <span style="color:#e6db74">'Sort output alphabetically'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
766
|
+
parameter <span style="color:#e6db74">:all</span>, <span style="color:#e6db74">'Show hidden files'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
767
|
+
parameter <span style="color:#e6db74">:directoriesfirst</span>, <span style="color:#e6db74">'Show directories on top'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
768
|
+
</code></pre></div><p>And let’s modify our action block to utilize them:</p>
|
|
769
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby"> action <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>params, args, global_opts, config<span style="color:#f92672">|</span>
|
|
770
|
+
filelist <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>
|
|
771
|
+
|
|
772
|
+
<span style="color:#75715e"># We include dotfiles if specified</span>
|
|
773
|
+
include_dotfiles <span style="color:#f92672">=</span> (params<span style="color:#f92672">[</span><span style="color:#e6db74">:all</span><span style="color:#f92672">]</span>) ? <span style="color:#66d9ef">File</span><span style="color:#f92672">::</span><span style="color:#66d9ef">FNM_DOTMATCH</span> : <span style="color:#ae81ff">0</span>
|
|
762
774
|
|
|
763
|
-
|
|
764
|
-
Dir
|
|
765
|
-
outname = filename
|
|
766
|
-
outname
|
|
767
|
-
filelist
|
|
768
|
-
end
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
filelist
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
if params[
|
|
775
|
-
files = []
|
|
776
|
-
filelist
|
|
777
|
-
if File
|
|
778
|
-
dirs
|
|
779
|
-
else
|
|
780
|
-
files
|
|
781
|
-
end
|
|
782
|
-
end
|
|
783
|
-
filelist = dirs
|
|
784
|
-
end
|
|
775
|
+
<span style="color:#75715e"># We store a list of the files in an array, including dotfiles if specified</span>
|
|
776
|
+
<span style="color:#66d9ef">Dir</span><span style="color:#f92672">.</span>glob <span style="color:#e6db74">"./*"</span>, include_dotfiles <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
777
|
+
outname <span style="color:#f92672">=</span> filename<span style="color:#f92672">.</span>split(<span style="color:#e6db74">'/'</span>)<span style="color:#f92672">[</span><span style="color:#ae81ff">1</span><span style="color:#f92672">]</span>
|
|
778
|
+
outname <span style="color:#f92672">+=</span> <span style="color:#e6db74">'/'</span> <span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
779
|
+
filelist<span style="color:#f92672">.</span>append outname
|
|
780
|
+
<span style="color:#66d9ef">end</span>
|
|
781
|
+
|
|
782
|
+
<span style="color:#75715e"># Sort alphabetically if specified</span>
|
|
783
|
+
filelist<span style="color:#f92672">.</span>sort! <span style="color:#66d9ef">if</span> params<span style="color:#f92672">[</span><span style="color:#e6db74">:sort</span><span style="color:#f92672">]</span>
|
|
784
|
+
|
|
785
|
+
<span style="color:#75715e"># Put directories first if specified</span>
|
|
786
|
+
<span style="color:#66d9ef">if</span> params<span style="color:#f92672">[</span><span style="color:#e6db74">:directoriesfirst</span><span style="color:#f92672">]</span>
|
|
787
|
+
files <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>; dirs <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>
|
|
788
|
+
filelist<span style="color:#f92672">.</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
789
|
+
<span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
790
|
+
dirs<span style="color:#f92672">.</span>append(filename)
|
|
791
|
+
<span style="color:#66d9ef">else</span>
|
|
792
|
+
files<span style="color:#f92672">.</span>append(filename)
|
|
793
|
+
<span style="color:#66d9ef">end</span>
|
|
794
|
+
<span style="color:#66d9ef">end</span>
|
|
795
|
+
filelist <span style="color:#f92672">=</span> dirs <span style="color:#f92672">+</span> files
|
|
796
|
+
<span style="color:#66d9ef">end</span>
|
|
785
797
|
|
|
786
|
-
|
|
787
|
-
filelist
|
|
788
|
-
if File
|
|
789
|
-
filename
|
|
790
|
-
elsif File
|
|
791
|
-
filename
|
|
792
|
-
else
|
|
798
|
+
<span style="color:#75715e"># Apply color. We do this at the end now because color codes can alter the sorting.</span>
|
|
799
|
+
filelist<span style="color:#f92672">.</span>map! <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
800
|
+
<span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
801
|
+
filename<span style="color:#f92672">.</span>light_blue
|
|
802
|
+
<span style="color:#66d9ef">elsif</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>executable? filename
|
|
803
|
+
filename<span style="color:#f92672">.</span>light_green
|
|
804
|
+
<span style="color:#66d9ef">else</span>
|
|
793
805
|
filename
|
|
794
|
-
end
|
|
795
|
-
end if global_opts[
|
|
806
|
+
<span style="color:#66d9ef">end</span>
|
|
807
|
+
<span style="color:#66d9ef">end</span> <span style="color:#66d9ef">if</span> global_opts<span style="color:#f92672">[</span><span style="color:#e6db74">:color</span><span style="color:#f92672">]</span>
|
|
796
808
|
|
|
797
809
|
puts filelist
|
|
798
|
-
end
|
|
799
|
-
</code></pre>
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
<pre><code class="language-bash">mytool -c list -asd
|
|
804
|
-
</code></pre>
|
|
805
|
-
|
|
806
|
-
<p>Note how the parameters come after the <code>list</code> command in the syntax above. As you create more commands, each will have its own unique set of parameters, while the options remain <em>before</em> the command and are available to all of them.</p>
|
|
807
|
-
|
|
810
|
+
<span style="color:#66d9ef">end</span>
|
|
811
|
+
</code></pre></div><p>You should be able to run it now:</p>
|
|
812
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">mytool -c list -asd
|
|
813
|
+
</code></pre></div><p>Note how the parameters come after the <code>list</code> command in the syntax above. As you create more commands, each will have its own unique set of parameters, while the options remain <em>before</em> the command and are available to all of them.</p>
|
|
808
814
|
<h3 id="user-prompting">User Prompting</h3>
|
|
809
|
-
|
|
810
815
|
<p>There is an additional option when declaring parameters to prompt the user for a value if not entered on the command line. This can be done with the <code>prompt:</code> keyword. Let’s change one of our parameters to utilize it:</p>
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
<p>Now, let’s run the tool while omitting the <code>--sort</code> parameter, as such:</p>
|
|
816
|
-
|
|
817
|
-
<pre><code class="language-bash">mytool -c list -ad
|
|
818
|
-
</code></pre>
|
|
819
|
-
|
|
820
|
-
<p>This should give you the prompt:</p>
|
|
821
|
-
|
|
816
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby">parameter <span style="color:#e6db74">:sort</span>, <span style="color:#e6db74">'Sort output alphabetically'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>, <span style="color:#e6db74">prompt</span>: <span style="color:#e6db74">"Sort output alphabetically?"</span>
|
|
817
|
+
</code></pre></div><p>Now, let’s run the tool while omitting the <code>--sort</code> parameter, as such:</p>
|
|
818
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">mytool -c list -ad
|
|
819
|
+
</code></pre></div><p>This should give you the prompt:</p>
|
|
822
820
|
<pre><code>Sort output alphabetically? (y/N):
|
|
823
|
-
</code></pre>
|
|
824
|
-
|
|
825
|
-
<p>Because we set the parameter to default to <code>false</code> the default here is <code>N</code>, which is used if the user hits enter without entering a letter. If the default was set to <code>true</code>, then the <code>Y</code> would be capitalized and be the default.</p>
|
|
826
|
-
|
|
821
|
+
</code></pre><p>Because we set the parameter to default to <code>false</code> the default here is <code>N</code>, which is used if the user hits enter without entering a letter. If the default was set to <code>true</code>, then the <code>Y</code> would be capitalized and be the default.</p>
|
|
827
822
|
<p>For more information, see the documentation on <a href="/rbcli/advanced/interactive_commands/">Interactive Commands</a>.</p>
|
|
828
|
-
|
|
829
823
|
<h2 id="arguments">Arguments</h2>
|
|
830
|
-
|
|
831
824
|
<p>Lastly on the command line, there are arguments. Arguments are simply strings without the <code>-</code> character in front, and automatically get passed into an array in your applicaiton. Let’s take a look at how we can use them.</p>
|
|
832
|
-
|
|
833
825
|
<p>Unlike options and parameters, arguments require no setup. So let’s assume that we want any arguments passed to the <code>list</code> command to be filenames that you want to display, and that you can pass multiple ones. Since arguments aren’t listed automatically by the help function, this is a good example of what to put in your usage text. Let’s take a look at what our class looks like now:</p>
|
|
834
|
-
|
|
835
|
-
<
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
parameter
|
|
843
|
-
parameter
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
include_dotfiles = (params[:all]) ? File::FNM_DOTMATCH : 0
|
|
826
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby"><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">List</span> <span style="color:#f92672"><</span> <span style="color:#66d9ef">Rbcli</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Command</span>
|
|
827
|
+
description <span style="color:#e6db74">%q{List files in current directory}</span>
|
|
828
|
+
usage <span style="color:#e6db74"><<-EOF
|
|
829
|
+
</span><span style="color:#e6db74"></span><span style="color:#66d9ef">To</span> list only specific files, you can enter filenames as arguments
|
|
830
|
+
|
|
831
|
+
mytool list filename1 filename2<span style="color:#f92672">...</span>
|
|
832
|
+
<span style="color:#66d9ef">EOF</span>
|
|
833
|
+
parameter <span style="color:#e6db74">:sort</span>, <span style="color:#e6db74">'Sort output alphabetically'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
834
|
+
parameter <span style="color:#e6db74">:all</span>, <span style="color:#e6db74">'Show hidden files'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
835
|
+
parameter <span style="color:#e6db74">:directoriesfirst</span>, <span style="color:#e6db74">'Show directories on top'</span>, <span style="color:#e6db74">type</span>: <span style="color:#e6db74">:boolean</span>, <span style="color:#e6db74">default</span>: <span style="color:#66d9ef">false</span>
|
|
836
|
+
|
|
837
|
+
action <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>params, args, global_opts, config<span style="color:#f92672">|</span>
|
|
838
|
+
filelist <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>
|
|
839
|
+
|
|
840
|
+
<span style="color:#75715e"># We include dotfiles if specified</span>
|
|
841
|
+
include_dotfiles <span style="color:#f92672">=</span> (params<span style="color:#f92672">[</span><span style="color:#e6db74">:all</span><span style="color:#f92672">]</span>) ? <span style="color:#66d9ef">File</span><span style="color:#f92672">::</span><span style="color:#66d9ef">FNM_DOTMATCH</span> : <span style="color:#ae81ff">0</span>
|
|
851
842
|
|
|
852
|
-
|
|
853
|
-
Dir
|
|
854
|
-
outname = filename
|
|
855
|
-
next unless args
|
|
856
|
-
outname
|
|
857
|
-
filelist
|
|
858
|
-
end
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
filelist
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
if params[
|
|
865
|
-
files = []
|
|
866
|
-
filelist
|
|
867
|
-
if File
|
|
868
|
-
dirs
|
|
869
|
-
else
|
|
870
|
-
files
|
|
871
|
-
end
|
|
872
|
-
end
|
|
873
|
-
filelist = dirs
|
|
874
|
-
end
|
|
843
|
+
<span style="color:#75715e"># We store a list of the files in an array, including dotfiles if specified</span>
|
|
844
|
+
<span style="color:#66d9ef">Dir</span><span style="color:#f92672">.</span>glob <span style="color:#e6db74">"./*"</span>, include_dotfiles <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
845
|
+
outname <span style="color:#f92672">=</span> filename<span style="color:#f92672">.</span>split(<span style="color:#e6db74">'/'</span>)<span style="color:#f92672">[</span><span style="color:#ae81ff">1</span><span style="color:#f92672">]</span>
|
|
846
|
+
<span style="color:#66d9ef">next</span> <span style="color:#66d9ef">unless</span> args<span style="color:#f92672">.</span>include? outname <span style="color:#66d9ef">if</span> args<span style="color:#f92672">.</span>length <span style="color:#f92672">></span> <span style="color:#ae81ff">0</span>
|
|
847
|
+
outname <span style="color:#f92672">+=</span> <span style="color:#e6db74">'/'</span> <span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
848
|
+
filelist<span style="color:#f92672">.</span>append outname
|
|
849
|
+
<span style="color:#66d9ef">end</span>
|
|
850
|
+
|
|
851
|
+
<span style="color:#75715e"># Sort alphabetically if specified</span>
|
|
852
|
+
filelist<span style="color:#f92672">.</span>sort! <span style="color:#66d9ef">if</span> params<span style="color:#f92672">[</span><span style="color:#e6db74">:sort</span><span style="color:#f92672">]</span>
|
|
853
|
+
|
|
854
|
+
<span style="color:#75715e"># Put directories first if specified</span>
|
|
855
|
+
<span style="color:#66d9ef">if</span> params<span style="color:#f92672">[</span><span style="color:#e6db74">:directoriesfirst</span><span style="color:#f92672">]</span>
|
|
856
|
+
files <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>; dirs <span style="color:#f92672">=</span> <span style="color:#f92672">[]</span>
|
|
857
|
+
filelist<span style="color:#f92672">.</span>each <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
858
|
+
<span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
859
|
+
dirs<span style="color:#f92672">.</span>append(filename)
|
|
860
|
+
<span style="color:#66d9ef">else</span>
|
|
861
|
+
files<span style="color:#f92672">.</span>append(filename)
|
|
862
|
+
<span style="color:#66d9ef">end</span>
|
|
863
|
+
<span style="color:#66d9ef">end</span>
|
|
864
|
+
filelist <span style="color:#f92672">=</span> dirs <span style="color:#f92672">+</span> files
|
|
865
|
+
<span style="color:#66d9ef">end</span>
|
|
875
866
|
|
|
876
|
-
|
|
877
|
-
filelist
|
|
878
|
-
if File
|
|
879
|
-
filename
|
|
880
|
-
elsif File
|
|
881
|
-
filename
|
|
882
|
-
else
|
|
867
|
+
<span style="color:#75715e"># Apply color. We do this at the end because color codes can alter the sorting</span>
|
|
868
|
+
filelist<span style="color:#f92672">.</span>map! <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>filename<span style="color:#f92672">|</span>
|
|
869
|
+
<span style="color:#66d9ef">if</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>directory? filename
|
|
870
|
+
filename<span style="color:#f92672">.</span>light_blue
|
|
871
|
+
<span style="color:#66d9ef">elsif</span> <span style="color:#66d9ef">File</span><span style="color:#f92672">.</span>executable? filename
|
|
872
|
+
filename<span style="color:#f92672">.</span>light_green
|
|
873
|
+
<span style="color:#66d9ef">else</span>
|
|
883
874
|
filename
|
|
884
|
-
end
|
|
885
|
-
end if global_opts[
|
|
875
|
+
<span style="color:#66d9ef">end</span>
|
|
876
|
+
<span style="color:#66d9ef">end</span> <span style="color:#66d9ef">if</span> global_opts<span style="color:#f92672">[</span><span style="color:#e6db74">:color</span><span style="color:#f92672">]</span>
|
|
886
877
|
|
|
887
878
|
puts filelist
|
|
888
|
-
end
|
|
889
|
-
end
|
|
890
|
-
</code></pre>
|
|
891
|
-
|
|
892
|
-
<h2 id="simplified-reference-tldr">Simplified Reference (TLDR)</h2>
|
|
893
|
-
|
|
879
|
+
<span style="color:#66d9ef">end</span>
|
|
880
|
+
<span style="color:#66d9ef">end</span>
|
|
881
|
+
</code></pre></div><h2 id="simplified-reference-tldr">Simplified Reference (TLDR)</h2>
|
|
894
882
|
<p>RBCli enforces a CLI structure of:</p>
|
|
895
|
-
|
|
896
883
|
<pre><code>toolname [options] command [parameters] argument1 argument2...
|
|
897
|
-
</code></pre>
|
|
898
|
-
|
|
899
|
-
<p><strong>Options</strong> are declared in <code>application/options.rb</code> file.</p>
|
|
900
|
-
|
|
884
|
+
</code></pre><p><strong>Options</strong> are declared in <code>application/options.rb</code> file.</p>
|
|
901
885
|
<p><strong>Parameters</strong> are declared in the respective command’s class declaration.</p>
|
|
902
|
-
|
|
903
886
|
<p><strong>Arguments</strong> don’t need to be declared, and are passed in as an array to your commands. It is helpful to describe the argument purpose in the <code>usage</code> text declaration so that the user can see what to do in the help.</p>
|
|
904
|
-
|
|
905
887
|
<p><strong>Options</strong> and <strong>parameters</strong> both use the same format:</p>
|
|
888
|
+
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-ruby" data-lang="ruby">option <span style="color:#e6db74">:<</span>name<span style="color:#f92672">></span>, <span style="color:#e6db74">"<description_string>"</span>, <span style="color:#e6db74">short</span>: <span style="color:#e6db74">'<character>'</span>, <span style="color:#e6db74">type</span>: <span style="color:#f92672"><</span>variable_type<span style="color:#f92672">></span>, <span style="color:#e6db74">default</span>: <span style="color:#f92672"><</span>default_value<span style="color:#f92672">></span>, <span style="color:#e6db74">permitted</span>: <span style="color:#f92672">[<</span>array_of_permitted_values<span style="color:#f92672">]</span>
|
|
906
889
|
|
|
907
|
-
<
|
|
908
|
-
|
|
909
|
-
parameter :<name>, "<description_string>", short: '<character>', type: <variable_type>, default: <default_value>, permitted: [<array_of_permitted_values]
|
|
910
|
-
</code></pre>
|
|
911
|
-
|
|
912
|
-
<ul>
|
|
890
|
+
parameter <span style="color:#e6db74">:<</span>name<span style="color:#f92672">></span>, <span style="color:#e6db74">"<description_string>"</span>, <span style="color:#e6db74">short</span>: <span style="color:#e6db74">'<character>'</span>, <span style="color:#e6db74">type</span>: <span style="color:#f92672"><</span>variable_type<span style="color:#f92672">></span>, <span style="color:#e6db74">default</span>: <span style="color:#f92672"><</span>default_value<span style="color:#f92672">></span>, <span style="color:#e6db74">permitted</span>: <span style="color:#f92672">[<</span>array_of_permitted_values<span style="color:#f92672">]</span>
|
|
891
|
+
</code></pre></div><ul>
|
|
913
892
|
<li><code>name</code>
|
|
914
|
-
|
|
915
893
|
<ul>
|
|
916
894
|
<li>(Required) The long name of the option, as a symbol. This will be represented as <code>--name</code> on the command line</li>
|
|
917
|
-
</ul
|
|
895
|
+
</ul>
|
|
896
|
+
</li>
|
|
918
897
|
<li><code>description_string</code>
|
|
919
|
-
|
|
920
898
|
<ul>
|
|
921
899
|
<li>(Required) A short description of the command that will appear in the help text for the user</li>
|
|
922
|
-
</ul
|
|
900
|
+
</ul>
|
|
901
|
+
</li>
|
|
923
902
|
<li><code>type</code>
|
|
924
|
-
|
|
925
903
|
<ul>
|
|
926
904
|
<li>(Required) The following types are supported: <code>:string</code>, <code>:boolean</code> or <code>:flag</code>, <code>:integer</code>, and <code>:float</code></li>
|
|
927
|
-
</ul
|
|
905
|
+
</ul>
|
|
906
|
+
</li>
|
|
928
907
|
<li><code>default</code>
|
|
929
|
-
|
|
930
908
|
<ul>
|
|
931
909
|
<li>(Optional) A default value for the option if one isn’t entered (default: nil)</li>
|
|
932
|
-
</ul
|
|
910
|
+
</ul>
|
|
911
|
+
</li>
|
|
933
912
|
<li><code>short</code>
|
|
934
|
-
|
|
935
913
|
<ul>
|
|
936
914
|
<li>(Optional) A letter that acts as a shortcut for the option. This will allow users to apply the command as <code>-n</code></li>
|
|
937
915
|
<li>To not have a short value, set this to :none (default: the first letter of the long name)</li>
|
|
938
|
-
</ul
|
|
916
|
+
</ul>
|
|
917
|
+
</li>
|
|
939
918
|
<li><code>required</code>
|
|
940
|
-
|
|
941
919
|
<ul>
|
|
942
920
|
<li>(Optional) Specify whether the option is required from the user (default: false)</li>
|
|
943
|
-
</ul
|
|
921
|
+
</ul>
|
|
922
|
+
</li>
|
|
944
923
|
<li><code>permitted</code>
|
|
945
|
-
|
|
946
924
|
<ul>
|
|
947
925
|
<li>(Optional) An array of whitelisted values for the option (default: nil)</li>
|
|
948
|
-
</ul></li>
|
|
949
926
|
</ul>
|
|
950
|
-
|
|
927
|
+
</li>
|
|
928
|
+
</ul>
|
|
951
929
|
<h2 id="next-steps">Next Steps</h2>
|
|
952
|
-
|
|
953
930
|
<p>Next, we’re going to take a quick look at how to publish and distribute your application, both publicly and within your organization.</p>
|
|
954
931
|
|
|
955
932
|
|
|
956
|
-
<footer class="
|
|
933
|
+
<footer class="footline">
|
|
957
934
|
|
|
958
935
|
</footer>
|
|
959
936
|
|
|
960
|
-
|
|
961
937
|
|
|
962
938
|
</div>
|
|
963
939
|
|
|
@@ -1385,20 +1361,19 @@ parameter :<name>, "<description_string>", short: '<cha
|
|
|
1385
1361
|
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;">
|
|
1386
1362
|
<div style="border: none; box-sizing: content-box; height: 200px; margin: 0px; padding: 0px; width: 200px;"></div>
|
|
1387
1363
|
</div>
|
|
1388
|
-
<script src="/rbcli/js/clipboard.min.js?
|
|
1389
|
-
<script src="/rbcli/js/perfect-scrollbar.min.js?
|
|
1390
|
-
<script src="/rbcli/js/perfect-scrollbar.jquery.min.js?
|
|
1391
|
-
<script src="/rbcli/js/jquery.sticky.js?
|
|
1392
|
-
<script src="/rbcli/js/featherlight.min.js?
|
|
1393
|
-
<script src="/rbcli/js/
|
|
1394
|
-
<script src="/rbcli/js/highlight.pack.js?1561087612"></script>
|
|
1364
|
+
<script src="/rbcli/js/clipboard.min.js?1596148729"></script>
|
|
1365
|
+
<script src="/rbcli/js/perfect-scrollbar.min.js?1596148729"></script>
|
|
1366
|
+
<script src="/rbcli/js/perfect-scrollbar.jquery.min.js?1596148729"></script>
|
|
1367
|
+
<script src="/rbcli/js/jquery.sticky.js?1596148729"></script>
|
|
1368
|
+
<script src="/rbcli/js/featherlight.min.js?1596148729"></script>
|
|
1369
|
+
<script src="/rbcli/js/highlight.pack.js?1596148729"></script>
|
|
1395
1370
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
1396
|
-
<script src="/rbcli/js/modernizr.custom-3.6.0.js?
|
|
1397
|
-
<script src="/rbcli/js/learn.js?
|
|
1398
|
-
<script src="/rbcli/js/hugo-learn.js?
|
|
1371
|
+
<script src="/rbcli/js/modernizr.custom-3.6.0.js?1596148729"></script>
|
|
1372
|
+
<script src="/rbcli/js/learn.js?1596148729"></script>
|
|
1373
|
+
<script src="/rbcli/js/hugo-learn.js?1596148729"></script>
|
|
1399
1374
|
|
|
1400
|
-
<link href="/rbcli/mermaid/mermaid.css?
|
|
1401
|
-
<script src="/rbcli/mermaid/mermaid.js?
|
|
1375
|
+
<link href="/rbcli/mermaid/mermaid.css?1596148729" rel="stylesheet" />
|
|
1376
|
+
<script src="/rbcli/mermaid/mermaid.js?1596148729"></script>
|
|
1402
1377
|
<script>
|
|
1403
1378
|
mermaid.initialize({ startOnLoad: true });
|
|
1404
1379
|
</script>
|