tty-option 0.2.0 → 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.
data/README.md CHANGED
@@ -9,34 +9,35 @@
9
9
  [![Build status](https://ci.appveyor.com/api/projects/status/gxml9ttyvgpeasy5?svg=true)][appveyor]
10
10
  [![Maintainability](https://api.codeclimate.com/v1/badges/1083a2fd114d6faf5d65/maintainability)][codeclimate]
11
11
  [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-option/badge.svg)][coverage]
12
- [![Inline docs](https://inch-ci.org/github/piotrmurach/tty-option.svg?branch=master)][inchpages]
13
12
 
14
13
  [gem]: https://badge.fury.io/rb/tty-option
15
14
  [gh_actions_ci]: https://github.com/piotrmurach/tty-option/actions?query=workflow%3ACI
16
15
  [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-option
17
16
  [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-option/maintainability
18
17
  [coverage]: https://coveralls.io/github/piotrmurach/tty-option
19
- [inchpages]: https://inch-ci.org/github/piotrmurach/tty-option
20
18
 
21
19
  > Parser for command line arguments, keywords, options and environment variables
22
20
 
23
21
  ## Features
24
22
 
25
- * Support for parsing of **positional arguments**, **keyword arguments**, **flags**, **options** and **environment variables**.
26
- * A convenient way to declare parsed parameters via **DSL** with a fallback to **hash-like syntax**.
27
- * Flexible parsing that **doesn't force any order for the parameters**.
28
- * Handling of complex option and keyword argument inputs like **lists** and **maps**.
29
- * Many **conversions types** provided out of the box, from basic integer to more complex hash structures.
30
- * Automatic **help generation** that can be customised with **usage** helpers like banner, examples and more.
31
- * Parsing **doesn't raise errors** by default and collects issues to allow for better user experience.
32
- * Ability to declare **global options** with inheritance that copies parameters to a child class.
23
+ * Parse command line **arguments**, **keywords**, **flags**, **options**
24
+ and **environment variables**.
25
+ * Define command line parameters with **DSL** or **keyword arguments**.
26
+ * Access all parameter values from hash-like **params**.
27
+ * Define **global parameters** with inheritance.
28
+ * Accept command line parameters in **any order**.
29
+ * Handle complex inputs like **lists** and **maps**.
30
+ * **Convert** inputs to basic and more complex object types.
31
+ * Generate **help** from parameter definitions.
32
+ * Customise help with **usage** methods such as **header**, **example** and more.
33
+ * Collect parsing **errors** for a better user experience.
33
34
 
34
35
  ## Installation
35
36
 
36
37
  Add this line to your application's Gemfile:
37
38
 
38
39
  ```ruby
39
- gem 'tty-option'
40
+ gem "tty-option"
40
41
  ```
41
42
 
42
43
  And then execute:
@@ -61,25 +62,27 @@ Or install it yourself as:
61
62
  * [2.5.3 default](#253-default)
62
63
  * [2.5.4 description](#254-description)
63
64
  * [2.5.5 hidden](#255-hidden)
64
- * [2.5.6 name](#256-name)
65
- * [2.5.7 optional](#257-optional)
66
- * [2.5.8 permit](#258-permit)
67
- * [2.5.9 required](#259-required)
68
- * [2.5.10 validate](#2510-validate)
65
+ * [2.5.6 long](#256-long)
66
+ * [2.5.7 name](#257-name)
67
+ * [2.5.8 optional](#258-optional)
68
+ * [2.5.9 permit](#259-permit)
69
+ * [2.5.10 required](#2510-required)
70
+ * [2.5.11 short](#2511-short)
71
+ * [2.5.12 validate](#2512-validate)
69
72
  * [2.6 parse](#26-parse)
70
73
  * [2.6.1 :raise_on_parse_error](#261-raise_on_parse_error)
71
74
  * [2.6.2 :check_invalid_params](#262-check_invalid_params)
72
75
  * [2.7 params](#27-params)
73
76
  * [2.7.1 errors](#271-errors)
74
77
  * [2.7.2 remaining](#272-remaining)
75
- * [2.7.3 valid?](#273-valid?)
78
+ * [2.7.3 valid?](#273-valid)
76
79
  * [2.8 usage](#28-usage)
77
80
  * [2.8.1 header](#281-header)
78
81
  * [2.8.2 program](#282-program)
79
82
  * [2.8.3 command](#283-command)
80
83
  * [2.8.4 banner](#284-banner)
81
84
  * [2.8.5 description](#285-description)
82
- * [2.8.6 example](#286-examples)
85
+ * [2.8.6 example](#286-example)
83
86
  * [2.8.7 footer](#287-footer)
84
87
  * [2.9 help](#29-help)
85
88
  * [2.9.1 sections](#291-sections)
@@ -90,11 +93,15 @@ Or install it yourself as:
90
93
 
91
94
  ## 1. Usage
92
95
 
93
- To start parsing command line parameters include `TTY::Option` module.
96
+ Include the `TTY::Option` module and define parameters to parse command
97
+ line input.
94
98
 
95
- Now, you're ready to define parsed parameters like arguments, keywords, flags, options or environment variables.
99
+ Choose from [arguments](#21-argument), [keywords](#22-keyword),
100
+ [flags](#23-option), [options](#23-option) and
101
+ [environment variables](#24-environment).
96
102
 
97
- For example, a quick demo to create a command that mixes all parameters usage:
103
+ For example, here is a quick demo of how to create a command that mixes
104
+ all parameter types:
98
105
 
99
106
  ```ruby
100
107
  class Command
@@ -132,18 +139,18 @@ class Command
132
139
  desc "Restart policy to apply when a container exits"
133
140
  end
134
141
 
135
- flag :help do
136
- short "-h"
137
- long "--help"
138
- desc "Print usage"
139
- end
140
-
141
142
  flag :detach do
142
143
  short "-d"
143
144
  long "--detach"
144
145
  desc "Run container in background and print container ID"
145
146
  end
146
147
 
148
+ flag :help do
149
+ short "-h"
150
+ long "--help"
151
+ desc "Print usage"
152
+ end
153
+
147
154
  option :name do
148
155
  required
149
156
  long "--name string"
@@ -161,7 +168,8 @@ class Command
161
168
  def run
162
169
  if params[:help]
163
170
  print help
164
- exit
171
+ elsif params.errors.any?
172
+ puts params.errors.summary
165
173
  else
166
174
  pp params.to_h
167
175
  end
@@ -175,21 +183,25 @@ Then create a command instance:
175
183
  cmd = Command.new
176
184
  ```
177
185
 
178
- And provided input from the command line:
186
+ And given the following input on the command line:
179
187
 
180
188
  ```
181
189
  restart=always -d -p 5000:3000 5001:8080 --name web ubuntu:16.4 bash
182
190
  ```
183
191
 
184
- Start parsing from `ARGV` or provide a custom array of inputs:
192
+ Read the command line input (aka `ARGV`) with [parse](#26-parse):
185
193
 
186
194
  ```ruby
187
195
  cmd.parse
188
- # or
196
+ ```
197
+
198
+ Or provide an array of inputs:
199
+
200
+ ```ruby
189
201
  cmd.parse(%w[restart=always -d -p 5000:3000 5001:8080 --name web ubuntu:16.4 bash])
190
202
  ```
191
203
 
192
- And run the command to see the values:
204
+ Finally, run the command to see parsed values:
193
205
 
194
206
  ```ruby
195
207
  cmd.run
@@ -201,22 +213,22 @@ cmd.run
201
213
  # :restart=>"always",
202
214
  # :image=>"ubuntu:16.4",
203
215
  # :command=>"bash"}
204
- ````
216
+ ```
205
217
 
206
- The `cmd` object also has a direct access to all the parameters via the `params`:
218
+ Use the [params](#27-params) to access all parameters:
207
219
 
208
220
  ```ruby
209
221
  cmd.params[:name] # => "web"
210
222
  cmd.params["command"] # => "bash
211
- ````
223
+ ```
212
224
 
213
- And when `--help` is found on the command line the run will print help:
225
+ Given the `--help` flag on the command line:
214
226
 
215
227
  ```ruby
216
- cmd.run
228
+ cmd.parse(%w[--help])
217
229
  ```
218
230
 
219
- To print help information to the terminal use `help` method:
231
+ Use the [help](#29-help) method to print help information to the terminal:
220
232
 
221
233
  ```ruby
222
234
  print cmd.help
@@ -251,335 +263,435 @@ Examples:
251
263
  $ dock run -v `pwd`:`pwd` -w `pwd` ubuntu pwd
252
264
  ```
253
265
 
266
+ Given an invalid command line input:
267
+
268
+ ```ruby
269
+ cmd.parse(%w[--unknown])
270
+ ```
271
+
272
+ Use the [errors](#271-errors) method to print all errors:
273
+
274
+ ```ruby
275
+ puts params.errors.summary
276
+ ```
277
+
278
+ This will print a summary of all errors:
279
+
280
+ ```
281
+ Errors:
282
+ 1) Invalid option '--unknown'
283
+ 2) Option '--publish' should appear at least 1 time but appeared 0 times
284
+ 3) Option '--name' must be provided
285
+ 4) Argument 'image' must be provided
286
+ ```
287
+
254
288
  ## 2. API
255
289
 
256
290
  ### 2.1 argument
257
291
 
258
- You can parse positional arguments with the `argument` method. To declare an argument you need to provide a name for the access key in the `params` like so:
292
+ Use the `argument` method to parse positional arguments.
293
+
294
+ Provide a name as a string or symbol to define an argument. The name will
295
+ serve as a default label for the help display and a key to retrieve
296
+ a value from the [params](#27-params):
259
297
 
260
298
  ```ruby
261
299
  argument :foo
262
300
  ```
263
301
 
264
- Then parsing command line input:
302
+ Given the following command line input:
265
303
 
266
304
  ```
267
305
  11 12 13
268
306
  ```
269
307
 
270
- Would result only in one argument parsed and the remaining ignored:
308
+ This would result only in one argument parsed and the remaining ignored:
271
309
 
272
310
  ```ruby
273
311
  params[:foo] # => "11"
274
312
  ```
275
313
 
276
- A more involved example to parse multiple positional arguments requires use of helper methods:
314
+ The `argument` method accepts a block to define
315
+ [parameter settings](#25-parameter-settings).
316
+
317
+ For example, use the [arity](#251-arity) and [convert](#252-convert) settings
318
+ to parse many positional arguments:
277
319
 
278
320
  ```ruby
279
321
  argument :foo do
280
- required # a default
281
- variable "foo(int)" # name for the usage display
282
- arity one_or_more # how many times to occur
283
- convert :int # values converted to integer
284
- validate -> { |v| v < 14 } # validation rule
285
- desc "Some foo desc" # description for the usage display
322
+ name "foo(int)" # name for help display
323
+ arity one_or_more # how many times can appear
324
+ convert :int_list # convert input to a list of integers
325
+ validate ->(v) { v < 14 } # validation rule
326
+ desc "Argument description" # description for help display
286
327
  end
287
328
  ```
288
329
 
289
- Parsing the previous input:
290
-
291
- ```bash
292
- 11 12 13
293
- ```
294
-
295
- Would result in all values being collected and converted to integers:
330
+ Parser would collect all values and convert them to integers given
331
+ previous input:
296
332
 
297
333
  ```ruby
298
- params[:foo] # => [11,12,13]
334
+ params[:foo] # => [11, 12, 13]
299
335
  ```
300
336
 
301
- The previous argument definition can also be written using hash syntax. This is especially useful if you want to specify arguments programmatically:
337
+ The `argument` method can also accept settings as keyword arguments:
302
338
 
303
339
  ```ruby
304
340
  argument :foo,
305
- required: true,
306
- variable: "foo(int)",
341
+ name: "foo(int)",
307
342
  arity: "+",
308
- convert: :int,
309
- validate: -> { |v| v < 14 },
310
- desc: "Some foo desc"
343
+ convert: :int_list,
344
+ validate: ->(v) { v < 14 },
345
+ desc: "Argument description"
311
346
  ```
312
347
 
313
- To read more about available settings see [parameter settings](#25-parameter-settings).
314
-
315
348
  ### 2.2 keyword
316
349
 
317
- To parse keyword arguments use the `keyword` method. To declare a keyword argument you need to provide a name for the key in the `params` like so:
350
+ Use the `keyword` method to parse keyword arguments.
351
+
352
+ Provide a name as a string or symbol to define a keyword argument. The name
353
+ will serve as a command line input name, a default label for the help
354
+ display and a key to retrieve a value from the [params](#27-params):
318
355
 
319
356
  ```ruby
320
357
  keyword :foo
321
358
  ```
322
359
 
323
- By default the keyword parameter name will be used as the keyword name on the command line:
360
+ Parser will use the parameter name to match the input name on the command
361
+ line by default.
362
+
363
+ Given the following command line input:
324
364
 
325
- ```bash
365
+ ```
326
366
  foo=11
327
367
  ```
328
368
 
329
- Parsing the above would result in:
369
+ This would result in:
330
370
 
331
371
  ```ruby
332
372
  params[:foo] # => "11"
333
373
  ```
334
374
 
335
- A more involved example to parse multiple keyword arguments requires use of helper methods:
336
-
337
- ```ruby
338
- keyword :foo do
339
- required # by default keywrod is not required
340
- arity one_or_more # how many times to occur
341
- convert :int # values converted to integer
342
- validate -> { |v| v < 14 } # validation rule
343
- desc "Some foo desc" # description for the usage display
344
- end
345
- ```
346
-
347
- Then provided the following command line input:
348
-
349
- ```bash
350
- foo=11 foo=12 foo=13
351
- ```
352
-
353
- The result would be:
375
+ Note that the parser performs no conversion of the value.
354
376
 
355
- ```ruby
356
- params[:foo] # => [11,12,13]
357
- ```
377
+ The `keyword` method accepts a block to define
378
+ [parameter settings](#25-parameter-settings).
358
379
 
359
- You can also specify for the keyword argument to accept a list type:
380
+ For example, use the [arity](#251-arity) and [convert](#252-convert)
381
+ settings to parse many keyword arguments:
360
382
 
361
383
  ```ruby
362
384
  keyword :foo do
363
385
  required # by default keyword is not required
364
- arity one_or_more # how many times to occur
365
- convert :int_list # input can be a list of integers
366
- validate -> { |v| v < 14 } # validation rule
367
- desc "Some foo desc" # description for the usage display
386
+ arity one_or_more # how many times can appear
387
+ convert :int_list # convert input to a list of integers
388
+ validate ->(v) { v < 14 } # validation rule
389
+ desc "Keyword description" # description for help display
368
390
  end
369
391
  ```
370
392
 
371
- Then command line input can contain a list as well:
393
+ Given the following command line input:
372
394
 
373
- ```bash
374
- foo=11 12 foo=13
395
+ ```
396
+ foo=10,11 foo=12 13
375
397
  ```
376
398
 
377
- Which will result in the same value:
399
+ This would result in an array of integers:
378
400
 
379
401
  ```ruby
380
- params[:foo] # => [11,12,13]
402
+ params[:foo] # => [10, 11, 12, 13]
381
403
  ```
382
404
 
383
- A keyword definition can be also a hash. This is especially useful if you intend to specify keyword arguments programmatically:
405
+ The `keyword` method can also accept settings as keyword arguments:
384
406
 
385
407
  ```ruby
386
408
  keyword :foo,
387
409
  required: true,
388
410
  arity: :+,
389
411
  convert: :int_list,
390
- validate: -> { |v| v < 14 },
391
- desc: "Some foo desc"
412
+ validate: ->(v) { v < 14 },
413
+ desc: "Keyword description"
392
414
  ```
393
415
 
394
- To read more about available settings see [parameter settings](#25-parameter-settings).
395
-
396
416
  ### 2.3 option
397
417
 
398
- To parse options and flags use the `option` or `flag` methods.
418
+ Use the `flag` or `option` methods to parse options.
399
419
 
400
- To declare an option you need to provide a name for the key used to access value in the `params`:
420
+ Provide a name as a string or symbol to define an option. The name will
421
+ serve as a command line input name, a label for the help display and
422
+ a key to retrieve a value from the [params](#27-params):
401
423
 
402
424
  ```ruby
403
425
  option :foo
404
426
  ```
405
427
 
406
- By default the option parameter name will be used to generate a long option name:
428
+ Parser will use the parameter name to generate a long option name by default.
429
+
430
+ Given the following command line input:
407
431
 
408
432
  ```
409
- --foo=11
433
+ --foo
410
434
  ```
411
435
 
412
- Parsing the above will result in:
436
+ This would result in:
413
437
 
414
438
  ```ruby
415
- params[:foo] # => "11"
439
+ params[:foo] # => true
416
440
  ```
417
441
 
418
- To specify a different name for the parsed option use the `short` and `long` helpers:
442
+ The `flag` and `option` methods accept a block to define
443
+ [parameter settings](#25-parameter-settings).
444
+
445
+ For example, to specify a different name for the parsed option,
446
+ use the [short](#2511-short) and [long](#256-long) settings:
419
447
 
420
448
  ```ruby
421
449
  option :foo do
422
- short "-f" # declares a short flag
423
- long "--foo" # declares a long flag
450
+ short "-f" # define a short name
451
+ long "--foo" # define a long name
424
452
  end
425
453
  ```
426
454
 
427
- If you wish for an option to accept an argument, you need to provide an extra label.
455
+ Given the following short name on the command line:
456
+
457
+ ```
458
+ -f
459
+ ```
460
+
461
+ This would result in:
462
+
463
+ ```
464
+ params[:foo] # => true
465
+ ```
466
+
467
+ An option can accept an argument. The argument can be either required
468
+ or optional. To define a required argument, provide an extra label
469
+ in `short` or `long` settings. The label can be any string. When
470
+ both `short` and `long` names are present, only specify an argument
471
+ for the long name.
428
472
 
429
- For example, for both short and long flag to require argument do:
473
+ For example, for both short and long names to accept a required
474
+ integer argument:
430
475
 
431
476
  ```ruby
432
477
  option :foo do
433
478
  short "-f"
434
- long "--foo string" # use any name after the flag name to specify required argument
479
+ long "--foo int"
435
480
  # or
436
- long "--foo=string" # you can also separate required argument with =
481
+ long "--foo=int"
437
482
  end
438
483
  ```
439
484
 
440
- To make a long option with an optional argument do:
485
+ Given the following command line input:
486
+
487
+ ```
488
+ --foo=11
489
+ ```
490
+
491
+ This would result in:
492
+
493
+ ```ruby
494
+ params[:foo] # => "11"
495
+ ```
496
+
497
+ Note that the parser performs no conversion of the argument.
498
+
499
+ To define an optional argument, surround it with square brackets.
500
+
501
+ For example, to accept an optional integer argument:
441
502
 
442
503
  ```ruby
443
504
  option :foo do
444
- long "--foo [string]" # use any name within square brackets to make argument optional
505
+ long "--foo [int]"
445
506
  end
446
507
  ```
447
508
 
448
- A more involved example that parses a list of integer may look like this:
509
+ Use the [arity](#251-arity) and [convert](#252-convert) settings to parse
510
+ many options given as a list of integers:
449
511
 
450
512
  ```ruby
451
513
  option :foo do
452
514
  required # by default option is not required
453
- arity one_or_more # how many times option can occur
454
- short "-f" # declares a short flag name
455
- long "--foo list" # declares a long flag with a required argument
456
- convert :int_list # input can be a list of integers
457
- validate -> { |v| v < 14 } # validation rule
458
- desc "Some foo desc" # description for the usage display
515
+ arity one_or_more # how many times option can appear
516
+ short "-f" # declare a short flag name
517
+ long "--foo ints" # declare a long flag with a required argument
518
+ convert :int_list # convert input to a list of integers
519
+ validate ->(v) { v < 14 } # validation rule
520
+ desc "Option description" # description for help display
459
521
  end
460
522
  ```
461
523
 
462
- Given command line input:
524
+ Given the following command line input:
463
525
 
464
- ```bash
526
+ ```
465
527
  --foo=10,11 -f 12 13
466
528
  ```
467
529
 
468
- The resulting value will be:
530
+ This would result in an array of integers:
469
531
 
470
532
  ```ruby
471
- params[:foo] # => [10,11,12,13]
533
+ params[:foo] # => [10, 11, 12, 13]
472
534
  ```
473
535
 
474
- An option definition can be declared as a hash as well. This is especially useful if you intend to specify options programmatically:
536
+ The option method can also accept settings as keyword arguments:
475
537
 
476
538
  ```ruby
477
539
  option :foo,
478
540
  required: true,
479
541
  arity: :+,
480
542
  short: "-f",
481
- long: "--foo list",
543
+ long: "--foo ints",
482
544
  convert: :int_list,
483
545
  validate: -> { |v| v < 14 },
484
- desc: "Some foo desc"
546
+ desc: "Option description"
547
+ ```
548
+
549
+ There is a convenience `flag` method to specify a command line option that
550
+ accepts no argument:
551
+
552
+ ```ruby
553
+ flag :foo
485
554
  ```
486
555
 
487
- To read more about available settings see [parameter settings](#25-parameter-settings).
556
+ For example, a typical scenario is to specify the help flag:
557
+
558
+ ```ruby
559
+ flag :help do
560
+ short "-h"
561
+ long "--help"
562
+ desc "Print usage"
563
+ end
564
+ ```
488
565
 
489
566
  ### 2.4 environment
490
567
 
491
- To parse environment variables use `environment` or `env` methods.
568
+ Use the `environment` or `env` methods to parse environment variables.
492
569
 
493
- By default, a parameter name will match a environment variable with the same name. For example, specifying a variable `:foo`:
570
+ Provide a name as a string or symbol to define an environment variable.
571
+ The name will serve as a command line input name, a default label for the
572
+ help display and a key to retrieve a value from the [params](#27-params):
494
573
 
495
574
  ```ruby
575
+ environment :foo
576
+ # or
496
577
  env :foo
497
578
  ```
498
579
 
499
- And then given the following command line input:
580
+ Parser will use the parameter name to match the input name on the command
581
+ line by default.
582
+
583
+ Given the following command line input:
500
584
 
501
585
  ```
502
- FOO=bar
586
+ FOO=11
503
587
  ```
504
588
 
505
- The resulting parameter would be:
589
+ The result would be:
506
590
 
507
591
  ```ruby
508
- params[:foo] # => "bar"
509
- ````
592
+ params[:foo] # => "11"
593
+ ```
594
+
595
+ Note that the parser performs no conversion of the value.
510
596
 
511
- To change the variable name to something else use `var` or `variable` helper:
597
+ The `environment` method accepts a block to define
598
+ [parameter settings](#25-parameter-settings).
599
+
600
+ For example, use the [name](#257-name) setting to change a default
601
+ variable name:
512
602
 
513
603
  ```ruby
514
- env :foo do
515
- var "FOO_ENV"
604
+ environment :foo do
605
+ name "FOO_ENV"
516
606
  end
517
607
  ```
518
608
 
519
- And then given a `FOO_ENV=bar` on the command line would result in:
609
+ Given the following command line input:
610
+
611
+ ```
612
+ FOO_ENV=11
613
+ ```
614
+
615
+ This would result in:
520
616
 
521
617
  ```ruby
522
- params[:foo] # => "bar"
618
+ params[:foo] # => "11"
523
619
  ```
524
620
 
525
- A more involved example that parses a list of integer may look like this:
621
+ For example, use the [arity](#251-arity) and [convert](#252-convert) settings
622
+ to parse many environment variables given as a list of integers:
526
623
 
527
624
  ```ruby
528
625
  environment :foo do
529
- required # by default environment is not required
530
- arity one_or_more # how many times env var can occur
531
- variable "FOO_ENV" # the command line input name
532
- convert map_of(:int) # input can be a map of integers
533
- validate -> { |v| v < 14 } # validation rule
534
- desc "Some foo desc" # description for the usage display
626
+ required # by default environment is not required
627
+ arity one_or_more # how many times env var can appear
628
+ name "FOO_ENV" # the command line input name
629
+ convert :int_list # convert input to a map of integers
630
+ validate ->(v) { v < 14 } # validation rule
631
+ desc "Environment description" # description for help display
535
632
  end
536
633
  ```
537
634
 
538
- Given command line input:
635
+ Given the following command line input:
539
636
 
540
- ```bash
541
- FOO_ENV=a:1&b:2 FOO_ENV=c=3 d=4
637
+ ```
638
+ FOO_ENV=10,11 FOO_ENV=12 13
542
639
  ```
543
640
 
544
- The resulting `params` would be:
641
+ This would result in an array of integers:
545
642
 
546
643
  ```ruby
547
- params[:foo] # => {a:1,b:2,c:3,d:4}
644
+ params[:foo] # => [10, 11, 12, 13]
548
645
  ```
549
646
 
550
- To read more about available settings see [parameter settings](#25-parameter-settings).
647
+ The `environment` method can also accept settings as keyword arguments:
648
+
649
+ ```ruby
650
+ environment :foo,
651
+ required: true,
652
+ arity: :+,
653
+ name: "FOO_ENV",
654
+ convert: :int_list,
655
+ validate: ->(v) { v < 14 },
656
+ desc: "Environment description"
657
+ ```
551
658
 
552
659
  ### 2.5 parameter settings
553
660
 
554
- These settings are supported by all parameter types with the exception of `short` and `long` which are specific to options only.
661
+ All parameter types support the following settings except for
662
+ `short` and `long`, which are [option](#23-option) specific.
555
663
 
556
664
  #### 2.5.1 arity
557
665
 
558
- To describe how many times a given parameter may appear in the command line use the `arity` setting.
666
+ Use the `arity` setting to describe how many times a given parameter may
667
+ appear on the command line.
559
668
 
560
- By default every parameter is assumed to appear only once. Any other occurrence will be disregarded and included in the remaining parameters list.
669
+ Every parameter can appear only once by default. In the case of arguments,
670
+ the parser will match the first input and ignore the rest. For other
671
+ parameter types, any extra parameter occurrence will override previously
672
+ parsed input. Setting the arity requirement overrides this behaviour.
561
673
 
562
- For example, to match argument exactly 2 times do:
674
+ For example, to match an argument exactly two times:
563
675
 
564
676
  ```ruby
565
677
  argument :foo do
566
678
  arity 2
567
679
  end
568
- ````
680
+ ```
569
681
 
570
- Then parsing from the command line:
682
+ Given the following command line input:
571
683
 
572
684
  ```ruby
573
685
  bar baz
574
686
  ```
575
687
 
576
- Will give the following:
688
+ This would result in an array of strings:
577
689
 
578
690
  ```ruby
579
691
  params[:foo] # => ["bar", "baz"]
580
692
  ```
581
693
 
582
- For parameters that expect a value, specifying arity will collect all the values matching arity requirement. For example, matching keywords:
694
+ Another example is to match exactly three occurrences of a keyword:
583
695
 
584
696
  ```ruby
585
697
  keyword :foo do
@@ -587,19 +699,22 @@ keyword :foo do
587
699
  end
588
700
  ```
589
701
 
590
- And then parsing the following:
702
+ And then given the following on the command line:
591
703
 
592
704
  ```
593
705
  foo=1 foo=2 foo=3
594
706
  ```
595
707
 
596
- Will produce:
708
+ This would result in an array of strings:
597
709
 
598
710
  ```ruby
599
711
  params[:foo] # => ["1", "2", "3"]
600
712
  ```
601
713
 
602
- To match any number of times use `:any`, `:*`, `-1`, `any` or `zero_or_more`:
714
+ Use `:any`, `:*`, `-1`, `any` or `zero_or_more` to specify that parameter
715
+ may appear any number of times.
716
+
717
+ For example, to expect an argument to appear zero or more times:
603
718
 
604
719
  ```ruby
605
720
  argument :foo do
@@ -607,17 +722,21 @@ argument :foo do
607
722
  end
608
723
  ```
609
724
 
610
- To match at at least one time use `:+` or `one_or_more`:
725
+ Use `:+` or `one_or_more` to specify that parameter must appear at least once.
726
+
727
+ For example, to expect an option with an argument to appear one or more times:
611
728
 
612
729
  ```ruby
613
730
  option :foo do
614
731
  arity one_or_more
615
- short "-b"
616
- long "--bar string"
732
+ short "-f"
733
+ long "--foo string"
617
734
  end
618
735
  ```
619
736
 
620
- You can also specify upper boundary with `at_least` helper as well:
737
+ Use `at_least` to specify the least number of times a parameter can appear:
738
+
739
+ For example, to expect a keyword to appear at least three times:
621
740
 
622
741
  ```ruby
623
742
  keyword :foo do
@@ -625,7 +744,9 @@ keyword :foo do
625
744
  end
626
745
  ```
627
746
 
628
- The [help](#29-help) method will handle the arity for the display. Given the following argument definition:
747
+ The [help](#29-help) method will handle the arity for the usage banner.
748
+
749
+ For example, given the following argument definition:
629
750
 
630
751
  ```ruby
631
752
  argument :foo do
@@ -633,7 +754,7 @@ argument :foo do
633
754
  end
634
755
  ```
635
756
 
636
- The usage banner will display:
757
+ The usage banner would display:
637
758
 
638
759
  ```
639
760
  Usage: foobar FOO [FOO...]
@@ -641,7 +762,11 @@ Usage: foobar FOO [FOO...]
641
762
 
642
763
  #### 2.5.2 convert
643
764
 
644
- You can convert any parameter argument to another type using the `convert` method with a predefined symbol or class name. For example, to convert an argument to integer you can do:
765
+ Use the `convert` setting to transform any parameter argument to another type.
766
+
767
+ The `convert` accepts a conversion name as a predefined symbol or class.
768
+
769
+ For example, to convert an argument to an integer:
645
770
 
646
771
  ```ruby
647
772
  argument :foo do
@@ -651,75 +776,89 @@ argument :foo do
651
776
  end
652
777
  ```
653
778
 
654
- The conversion types that are supported:
779
+ The supported conversion types are:
655
780
 
656
- * `:boolean`|`:bool` - e.g. 'yes/1/y/t/' becomes `true`, 'no/0/n/f' becomes `false`
657
- * `:date` - parses dates formats "28/03/2020", "March 28th 2020"
781
+ * `:bool` or `:boolean` - e.g. `yes,1,y,t` becomes `true`,
782
+ `no,0,n,f` becomes `false`
783
+ * `:date` - e.g. `28/03/2020` becomes `#<Date: 2020-03-28...>`
658
784
  * `:float` - e.g. `-1` becomes `-1.0`
659
- * `:int`|`:integer` - e.g. `+1` becomes `1`
660
- * `:path`|`:pathname` - converts to `Pathname` object
661
- * `:regexp` - e.g. "foo|bar" becomes `/foo|bar/`
662
- * `:uri` - converts to `URI` object
663
- * `:sym`|`:symbol` - e.g. "foo" becomes `:foo`
664
- * `:list`|`:array` - e.g. 'a,b,c' becomes `["a", "b", "c"]`
665
- * `:map`|`:hash` - e.g. 'a:1 b:2 c:3' becomes `{a: "1", b: "2", c: "3"}`
785
+ * `:int` or `:integer` - e.g. `+1` becomes `1`
786
+ * `:path` or `:pathname` - e.g. `/foo/bar/baz` becomes
787
+ `#<Pathname:/foo/bar/baz>`
788
+ * `:regex` or `:regexp` - e.g. `foo|bar` becomes `/foo|bar/`
789
+ * `:uri` - e.g. `foo.com` becomes `#<URI::Generic foo.com>`
790
+ * `:sym` or `:symbol` - e.g. `foo` becomes `:foo`
791
+ * `:list` or `:array` - e.g. `a,b,c` becomes `["a", "b", "c"]`
792
+ * `:map` or `:hash` - e.g. `a:1 b:2 c:3` becomes `{a: "1", b: "2", c: "3"}`
666
793
 
667
- In addition you can specify a plural or append `list` to any base type:
794
+ To convert to an array of a given type, specify plural or append an `array`
795
+ or`list` to any base type:
668
796
 
669
- * `:ints` or `:int_list` - will convert to a list of integers
670
- * `:floats` or `:float_list` - will convert to a list of floats
671
- * `:bools` or `:bool_list` - will convert to a list of booleans, e.g. `t,f,t` becomes `[true, false, true]`
797
+ * `:bools`, `:bool_array` or `:bool_list` - e.g. `t,f,t` becomes
798
+ `[true, false, true]`
799
+ * `:floats`, `:float_array` or `:float_list` - e.g. `1,2,3` becomes
800
+ `[1.0, 2.0, 3.0]`
801
+ * `:ints`, `:int_array` or `:int_list` - e.g. `1,2,3` becomes `[1, 2, 3]`
672
802
 
673
- If like you can also use `list_of` helper and pass the type as a first argument.
803
+ Or, use the `list_of` method and pass the type as a first argument.
674
804
 
675
- Similarly, you can append `map` to any base type:
805
+ To convert to a hash with values of a given type, append a `hash` or `map` to
806
+ any base type:
676
807
 
677
- * `:int_map` - will convert to a map of integers, e.g `a:1 b:2 c:3` becomes `{a: 1, b: 2, c: 3}`
678
- * `:bool_map` - will convert to a map of booleans, e.g `a:t b:f c:t` becomes `{a: true, b: false, c: true}`
808
+ * `:bool_hash` or `:bool_map` - e.g `a:t b:f c:t` becomes
809
+ `{a: true, b: false, c: true}`
810
+ * `:float_hash` or `:float_map` - e.g `a:1 b:2 c:3` becomes
811
+ `{a: 1.0, b: 2.0, c: 3.0}`
812
+ * `:int_hash` or `:int_map` - e.g `a:1 b:2 c:3` becomes `{a: 1, b: 2, c: 3}`
679
813
 
680
- For convenience and readability you can also use `map_of` helper and pass the type as a first argument.
814
+ Or, use the `map_of` method and pass the type as a first argument.
681
815
 
682
- For example, to parse options with required list and map arguments:
816
+ For example, given options with a required list and map arguments:
683
817
 
684
818
  ```ruby
685
819
  option :foo do
686
- long "--foo map"
687
- convert :bools # or `convert list_of(:bool)`
820
+ long "--foo list"
821
+ convert :bools
822
+ # or
823
+ convert list_of(:bool)
688
824
  end
689
825
 
690
826
  option :bar do
691
- long "--bar int map"
692
- convert :int_map # or `conert map_of(:int)`
827
+ long "--bar map"
828
+ convert :int_map
829
+ # or
830
+ convert map_of(:int)
693
831
  end
694
- ````
832
+ ```
695
833
 
696
- And then parsing the following:
834
+ And then parsing the following command line input:
697
835
 
698
- ```bash
836
+ ```
699
837
  --foo t,f,t --bar a:1 b:2 c:3
700
838
  ```
701
839
 
702
- Will give the following:
840
+ This would result in an array of booleans and a hash with integer values:
703
841
 
704
842
  ```ruby
705
- params[:foo]
706
- # => [true, false, true]
707
- params[:bar]
708
- # => {:a=>1, :b=>2, :c=>3}
709
- ````
843
+ params[:foo] # => [true, false, true]
844
+ params[:bar] # => {:a=>1, :b=>2, :c=>3}
845
+ ```
710
846
 
711
- You can also provide `proc` to define your own custom conversion:
847
+ Use a `Proc` object to define custom conversion.
848
+
849
+ For example, to convert the command line input to uppercase:
712
850
 
713
851
  ```ruby
714
- option :bar do
715
- long "--bar string"
852
+ option :foo do
853
+ long "--foo string"
716
854
  convert ->(val) { val.upcase }
717
855
  end
718
856
  ```
719
857
 
720
858
  #### 2.5.3 default
721
859
 
722
- Any optional parameter such as options, flag, keyword or environment variable, can have a default value. This value can be specified with the `default` setting and will be used when the command-line input doesn't match any parameter definitions.
860
+ Use the `default` setting to specify a default value for an optional parameter.
861
+ The parser will use default when the command line input isn't present.
723
862
 
724
863
  For example, given the following option definition:
725
864
 
@@ -730,13 +869,14 @@ option :foo do
730
869
  end
731
870
  ```
732
871
 
733
- When no option `--foo` is parsed, then the `params` will be populated:
872
+ When the option `--foo` isn't present on the command line, the `params`
873
+ will have a default value set:
734
874
 
735
875
  ```ruby
736
876
  params[:foo] # => "bar"
737
877
  ```
738
878
 
739
- The default can also be specified with a `proc` object:
879
+ Or, use a `Proc` object to specify a default value:
740
880
 
741
881
  ```ruby
742
882
  option :foo do
@@ -745,47 +885,55 @@ option :foo do
745
885
  end
746
886
  ```
747
887
 
748
- A parameter cannot be both required and have default value. Specifying both will raise `ConfigurationError`. For example, all positional arguments are required by default. If you want to have a default for a required argument make it `optional`:
888
+ A parameter cannot be both required and have a default value. This will raise
889
+ `ConfigurationError`. The parser treats positional arguments as required.
890
+ To have a default for a required argument make it [optional](#258-optional):
749
891
 
750
892
  ```ruby
751
893
  argument :foo do
752
894
  optional
753
895
  default "bar"
754
- desc "Some description"
896
+ desc "Argument description"
755
897
  end
756
898
  ```
757
899
 
758
- The default will be automatically displayed in the usage information:
900
+ The usage description for a given parameter will display the default value:
759
901
 
760
902
  ```
761
- Usage: foobar [OPTIONS] [FOO]
903
+ Usage: foobar [FOO]
762
904
 
763
905
  Arguments:
764
- FOO Some description (default "bar")
906
+ FOO Argument description (default "bar")
765
907
  ```
766
908
 
767
- #### 2.5.4 desc(ription)
909
+ #### 2.5.4 description
768
910
 
769
- To provide a synopsis for a parameter use the `description` or shorter `desc` setting. This information is used by the [help](#29-help) method to produce usage information:
911
+ Use the `description` or `desc` setting to provide a summary for
912
+ a parameter. The [help](#29-help) method uses a parameter
913
+ description to generate a usage display.
914
+
915
+ For example, given an option with a description:
770
916
 
771
917
  ```ruby
772
918
  option :foo do
773
- desc "Some description"
919
+ desc "Option description"
774
920
  end
775
921
  ```
776
922
 
777
- The above will result in:
923
+ This will result in the following help display:
778
924
 
779
925
  ```
780
926
  Usage: foobar [OPTIONS]
781
927
 
782
928
  Options:
783
- --foo Some description
929
+ --foo Option description
784
930
  ```
785
931
 
786
932
  #### 2.5.5 hidden
787
933
 
788
- To hide a parameter from display in the usage information use the `hidden` setting:
934
+ Use the `hidden` setting to hide a parameter from the [help](#29-help) display.
935
+
936
+ For example, given a standard argument and a hidden one:
789
937
 
790
938
  ```ruby
791
939
  argument :foo
@@ -795,55 +943,140 @@ argument :bar do
795
943
  end
796
944
  ```
797
945
 
798
- The above will hide the `:bar` parameter from the usage:
946
+ The above will hide the `:bar` parameter from the usage banner:
799
947
 
800
948
  ```
801
949
  Usage: foobar FOO
802
950
  ```
803
951
 
804
- #### 2.5.6 name
952
+ #### 2.5.6 long
953
+
954
+ Only [flag](#23-option) and [option](#23-option) parameters can use
955
+ the `long` setting.
956
+
957
+ Use the `long` setting to define a long name for an option. By convention,
958
+ a long name uses a double dash followed by many characters.
959
+
960
+ When you don't specify a short or long name, the parameter name
961
+ will serve as the option's long name by default.
962
+
963
+ For example, to define the `--foo` option:
964
+
965
+ ```ruby
966
+ option :foo
967
+ ```
968
+
969
+ To change the default name to the `--fuu` option:
970
+
971
+ ```ruby
972
+ option :foo do
973
+ long "--fuu"
974
+ end
975
+ ```
976
+
977
+ A long option can accept an argument. The argument can be either required
978
+ or optional. To define a required argument, separate it from the option
979
+ name with a space or an equal sign.
980
+
981
+ For the `:foo` option to accept a required integer argument:
982
+
983
+ ```ruby
984
+ option :foo do
985
+ long "--foo int"
986
+ end
987
+ ```
988
+
989
+ These are all equivalent ways to define a long option with a required
990
+ argument:
991
+
992
+ ```ruby
993
+ long "--foo int"
994
+ long "--foo=int"
995
+ ```
996
+
997
+ To define an optional argument, surround it with square brackets. Like
998
+ the required argument, separate it from the option name with a space
999
+ or an equal sign. It is possible to skip the space, but that would
1000
+ make the option description hard to read.
1001
+
1002
+ For the `:foo` option to accept an optional integer argument:
1003
+
1004
+ ```ruby
1005
+ option :foo do
1006
+ long "--foo [int]"
1007
+ end
1008
+ ```
1009
+
1010
+ These are all equivalent ways to define a long option with
1011
+ an optional argument:
805
1012
 
806
- By default the parameter key will be used to match command-line input arguments.
1013
+ ```ruby
1014
+ long "--foo [int]"
1015
+ long "--foo=[int]"
1016
+ long "--foo[int]"
1017
+ ```
1018
+
1019
+ When specifying short and long option names, only define the argument
1020
+ for the long name.
1021
+
1022
+ For example, to define an option with short and long names that accepts
1023
+ a required integer argument:
1024
+
1025
+ ```ruby
1026
+ option :foo do
1027
+ short "-f"
1028
+ long "--foo int"
1029
+ end
1030
+ ```
1031
+
1032
+ Note that the parser performs no conversion of the argument. Use the
1033
+ [convert](#252-convert) setting to transform the argument type.
807
1034
 
808
- This means that a key `:foo_bar` will match `"foo-bar"` parameter name. For example, given a keyword:
1035
+ #### 2.5.7 name
1036
+
1037
+ The parser will use a parameter name to match command line inputs by default.
1038
+ It will convert underscores in a name into dashes when matching input.
1039
+
1040
+ For example, given the `:foo_bar` keyword definition:
809
1041
 
810
1042
  ```ruby
811
1043
  keyword :foo_bar
812
1044
  ```
813
1045
 
814
- And then command-line input:
1046
+ And the following command line input:
815
1047
 
816
1048
  ```
817
1049
  foo-bar=baz
818
1050
  ```
819
1051
 
820
- The parsed result will be:
1052
+ This would result in:
821
1053
 
822
1054
  ```ruby
823
1055
  params[:foo_bar] # => "baz"
824
1056
  ```
825
1057
 
826
- To change the parameter name to a custom one, use the `name` setting:
1058
+ Use the `name` setting to change the parameter default input name.
827
1059
 
828
1060
  ```ruby
829
- keywor :foo_bar do
1061
+ keyword :foo_bar do
830
1062
  name "fum"
831
1063
  end
832
1064
  ```
833
1065
 
834
- Then parsing:
1066
+ Given the following command line input:
835
1067
 
836
1068
  ```
837
1069
  fum=baz
838
1070
  ```
839
1071
 
840
- Will result in:
1072
+ This would result in:
841
1073
 
1074
+ ```ruby
1075
+ params[:foo_bar] # => "baz"
842
1076
  ```
843
- params[:foo] # => "baz"
844
- ````
845
1077
 
846
- For environment variables use the upper case when changing name:
1078
+ Use uppercase characters when changing the input name for
1079
+ environment variables:
847
1080
 
848
1081
  ```ruby
849
1082
  env :foo do
@@ -851,105 +1084,137 @@ env :foo do
851
1084
  end
852
1085
  ```
853
1086
 
854
- #### 2.5.7 optional
1087
+ #### 2.5.8 optional
1088
+
1089
+ All parameters are optional apart from positional arguments.
855
1090
 
856
- Apart from the positional argument, all other parameters are optional. To mark an argument as optional use similar naming `optional` setting:
1091
+ Use the `optional` setting to mark a parameter as optional.
1092
+
1093
+ For example, given a required argument and an optional one:
857
1094
 
858
1095
  ```ruby
859
1096
  argument :foo do
860
- desc "Foo arg description"
1097
+ desc "Foo argument description"
861
1098
  end
862
1099
 
863
1100
  argument :bar do
864
1101
  optional
865
- desc "Bar arg description"
1102
+ desc "Bar argument description"
866
1103
  end
867
1104
  ```
868
1105
 
869
- The optional argument will be surrounded by brackets in the usage display:
1106
+ And given the following command line input:
1107
+
1108
+ ```
1109
+ baz
1110
+ ```
1111
+
1112
+ This would result in:
1113
+
1114
+ ```ruby
1115
+ params[:foo] # => "baz"
1116
+ params[:bar] # => nil
1117
+ ```
1118
+
1119
+ The usage banner will display an optional argument surrounded by brackets:
870
1120
 
871
1121
  ```
872
- Usage: foobar [OPTIONS] FOO [BAR]
1122
+ Usage: foobar FOO [BAR]
873
1123
 
874
1124
  Arguments:
875
- FOO Foo arg description
876
- BAR Bar arg description
1125
+ FOO Foo argument description
1126
+ BAR Bar argument description
877
1127
  ```
878
1128
 
879
- #### 2.5.8 permit
1129
+ #### 2.5.9 permit
880
1130
 
881
- The `permit` setting allows you to restrict an input to a set of possible values.
1131
+ Use the `permit` setting to restrict input to a set of possible values.
882
1132
 
883
- For example, let's restrict option to only `"bar"` and `"baz"` strings:
1133
+ For example, to restrict the `:foo` option to only `"bar"` and `"baz"` strings:
884
1134
 
885
1135
  ```ruby
886
1136
  option :foo do
887
1137
  long "--foo string"
888
- permit ["bar", "baz"]
1138
+ permit %w[bar baz]
889
1139
  end
890
1140
  ```
891
1141
 
892
- And then parsing
1142
+ Given the following command line input:
893
1143
 
894
1144
  ```
895
1145
  --foo bar
896
1146
  ```
897
1147
 
898
- Will populate parameters value:
1148
+ This would result in:
899
1149
 
900
1150
  ```ruby
901
1151
  params[:foo] # => "bar"
902
1152
  ```
903
1153
 
904
- Attempting to parse not permitted value:
1154
+ Given not permitted value `qux` on the command line:
905
1155
 
906
1156
  ```
907
1157
  --foo qux
908
1158
  ```
909
1159
 
910
- Will internally produce a `TTY::Option::UnpermittedArgument` error and make the `params` invalid.
1160
+ This would raise a `TTY::Option::UnpermittedArgument` error and
1161
+ make the [params](#27-params) invalid.
911
1162
 
912
- Permitted values are checked after applying conversion. Because of this, you need to provide the expected type for the `permit` setting:
1163
+ The parser checks permitted values after applying conversion first. Because
1164
+ of this, permit setting needs its values to be already of the correct type.
1165
+
1166
+ For example, given integer conversion, permitted values need to
1167
+ be integers as well:
913
1168
 
914
1169
  ```ruby
915
1170
  option :foo do
916
1171
  long "--foo int"
917
- confert :int
1172
+ convert :int
918
1173
  permit [11, 12, 13]
919
1174
  end
920
1175
  ```
921
1176
 
922
- Then parsing an unpermitted value:
1177
+ Then given not permitted integer:
923
1178
 
924
1179
  ```
925
1180
  --foo 14
926
1181
  ```
927
1182
 
928
- Will invalidate `params` and collect the `TTY::Option::UnpermittedArgument` error.
1183
+ This would invalidate `params` and collect the
1184
+ `TTY::Option::UnpermittedArgument` error.
929
1185
 
930
- The permitted values are automatically appended to the parameter synopsis when displayed in the usage information. For example, given an option:
1186
+ The [help](#29-help) method displays permitted values in the
1187
+ parameter description.
1188
+
1189
+ For example, given the following option:
931
1190
 
932
1191
  ```ruby
933
1192
  option :foo do
934
1193
  short "-f"
935
1194
  long "--foo string"
936
1195
  permit %w[a b c d]
937
- desc "Some description"
1196
+ desc "Option description"
938
1197
  end
939
1198
  ```
940
1199
 
941
- Then the usage information for the option would be:
1200
+ Then the description for the option would be:
942
1201
 
943
1202
  ```
944
1203
  Usage: foobar [OPTIONS]
945
1204
 
946
1205
  Options:
947
- -f, --foo string Some description (permitted: a,b,c,d)
1206
+ -f, --foo string Option description (permitted: a, b, c, d)
948
1207
  ```
949
1208
 
950
- #### 2.5.9 required
1209
+ #### 2.5.10 required
1210
+
1211
+ Parser only requires arguments to be present on the command line by default.
1212
+ Any other parameters like options, keywords and environment variables
1213
+ are optional.
951
1214
 
952
- Only arguments are required. Any other parameters like options, keywords and environment variables are optional. To force parameter presence in input use `required` setting.
1215
+ Use the `required` setting to force parameter presence in command line input.
1216
+
1217
+ For example, given a required keyword and an optional one:
953
1218
 
954
1219
  ```ruby
955
1220
  keyword :foo do
@@ -962,7 +1227,38 @@ keyword :bar do
962
1227
  end
963
1228
  ```
964
1229
 
965
- Because `foo` keyword is required it won't have brackets around the parameter in the usage display:
1230
+ And given the following command line input:
1231
+
1232
+ ```
1233
+ foo=baz
1234
+ ```
1235
+
1236
+ This would result in:
1237
+
1238
+ ```ruby
1239
+ params[:foo] # => "baz"
1240
+ params[:bar] # => nil
1241
+ ```
1242
+
1243
+ Given the following command line input without the `foo` keyword:
1244
+
1245
+ ```
1246
+ bar=baz
1247
+ ```
1248
+
1249
+ This would raise a `TTY::Option::MissingParameter` error.
1250
+
1251
+ Then printing [errors](#271-errors) summary would display the following
1252
+ error description:
1253
+
1254
+ ```
1255
+ Error: keyword 'foo' must be provided
1256
+ ```
1257
+
1258
+ The usage banner displays the required parameters first. Then surrounds any
1259
+ optional parameters in brackets.
1260
+
1261
+ The [help](#29-help) display for the above keywords would be:
966
1262
 
967
1263
  ```
968
1264
  Usage: foobar FOO=FOO [BAR=BAR]
@@ -972,56 +1268,148 @@ Keywords:
972
1268
  BAR=BAR Bar keyword description
973
1269
  ```
974
1270
 
975
- Note: Using required options is rather discouraged as these are typically expected to be optional.
1271
+ #### 2.5.11 short
1272
+
1273
+ Only [flag](#23-option) and [option](#23-option) parameters can use
1274
+ the `short` setting.
1275
+
1276
+ Use the `short` setting to define a short name for an option. By convention,
1277
+ a short name uses a single dash followed by a single alphanumeric character.
1278
+
1279
+ For example, to define the `-f` option:
1280
+
1281
+ ```ruby
1282
+ option :foo do
1283
+ short "-f"
1284
+ end
1285
+ ```
1286
+
1287
+ A short option can accept an argument. The argument can be either required
1288
+ or optional. To define a required argument, separate it from the option
1289
+ name with a space or an equal sign. It is possible to skip the space,
1290
+ but that would make the option description hard to read.
1291
+
1292
+ For the `:foo` option to accept a required integer argument:
1293
+
1294
+ ```ruby
1295
+ option :foo do
1296
+ short "-f int"
1297
+ end
1298
+ ```
1299
+
1300
+ These are all equivalent ways to define a short option with a required
1301
+ argument:
1302
+
1303
+ ```ruby
1304
+ short "-f int"
1305
+ short "-f=int"
1306
+ short "-fint"
1307
+ ```
1308
+
1309
+ To define an optional argument, surround it with square brackets. Like
1310
+ the required argument, separate it from the option name with a space
1311
+ or an equal sign. It is possible to skip the space, but that would
1312
+ make the option description hard to read.
1313
+
1314
+ For the `:foo` option to accept an optional integer argument:
1315
+
1316
+ ```ruby
1317
+ option :foo do
1318
+ short "-f [int]"
1319
+ end
1320
+ ```
1321
+
1322
+ These are all equivalent ways to define a short option with
1323
+ an optional argument:
1324
+
1325
+ ```ruby
1326
+ short "-f [int]"
1327
+ short "-f=[int]"
1328
+ short "-f[int]"
1329
+ ```
1330
+
1331
+ When specifying short and long option names, only define the argument
1332
+ for the long name.
1333
+
1334
+ For example, to define an option with short and long names that accepts
1335
+ a required integer argument:
1336
+
1337
+ ```ruby
1338
+ option :foo do
1339
+ short "-f"
1340
+ long "--foo int"
1341
+ end
1342
+ ```
1343
+
1344
+ Note that the parser performs no conversion of the argument. Use
1345
+ the [convert](#252-convert) setting to transform the argument type.
976
1346
 
977
- #### 2.5.10 validate
1347
+ #### 2.5.12 validate
978
1348
 
979
- Use the `validate` setting if you wish to ensure only inputs matching filter criteria are allowed.
1349
+ Use the `validate` setting to ensure that inputs match a validation rule.
1350
+ The rule can be a string, a regular expression or a `Proc` object.
980
1351
 
981
- You can use a string or regular expression to describe your validation rule:
1352
+ For example, to ensure the `--foo` option only accepts digits:
982
1353
 
983
1354
  ```ruby
984
1355
  option :foo do
985
- long "--foo VAL"
1356
+ long "--foo int"
986
1357
  validate "\d+"
987
1358
  end
988
1359
  ```
989
1360
 
990
- Then parsing:
1361
+ Given the following command line input:
991
1362
 
992
1363
  ```
993
1364
  --foo bar
994
1365
  ```
995
1366
 
996
- Will internally cause an exception `TTY::Option::InvalidArgument` that will make `params` invalid.
1367
+ This would raise a `TTY::Option::InvalidArgument` error that would
1368
+ make `params` invalid.
1369
+
1370
+ Then printing [errors](#271-errors) summary would output:
997
1371
 
998
- You can also express a validation rule with a `proc` object:
1372
+ ```
1373
+ Error: value of `bar` fails validation for '--foo' option
1374
+ ```
1375
+
1376
+ To define a validation rule as a `Proc` object that accepts
1377
+ an argument to check:
999
1378
 
1000
1379
  ```ruby
1001
1380
  keyword :foo do
1002
- arity one_or_more
1003
1381
  convert :int
1004
1382
  validate ->(val) { val < 12 }
1005
1383
  end
1006
1384
  ```
1007
1385
 
1008
- Then parsing:
1386
+ The parser validates a value after applying conversion first. Because of
1387
+ this, the value inside a validation rule is already of the correct type.
1388
+
1389
+ Given the following command line input:
1009
1390
 
1010
1391
  ```
1011
- foo=11 foo=13
1392
+ foo=13
1012
1393
  ```
1013
1394
 
1014
- Will similarly collect the `TTY::Option::InvalidArgument` error and render `params` invalid.
1395
+ This would raise a `TTY::Option::InvalidArgument` error and make
1396
+ `params` invalid.
1015
1397
 
1016
- ### 2.6 parse
1398
+ Then using the [errors](#271-errors) summary would print the following error:
1399
+
1400
+ ```
1401
+ Error: value of `13` fails validation for 'foo' keyword
1402
+ ```
1017
1403
 
1018
- After all parameters are defined, use the `parse` to process command line inputs.
1404
+ ### 2.6 parse
1019
1405
 
1020
- By default the `parse` method takes the input from the `ARGV` and the `ENV` variables.
1406
+ Use the `parse` method to match command line inputs against defined parameters.
1021
1407
 
1022
- Alternatively, you can call `parse` with custom inputs. This is especially useful for testing your commands.
1408
+ The `parse` method reads the input from the command line (aka `ARGV`) and
1409
+ the environment variables (aka `ENV`) by default. It also accepts inputs
1410
+ as an argument. This is useful when testing commands.
1023
1411
 
1024
- Given parameter definitions:
1412
+ For example, given the following parameter definitions:
1025
1413
 
1026
1414
  ```ruby
1027
1415
  argument :foo
@@ -1033,13 +1421,13 @@ keyword :baz
1033
1421
  env :qux
1034
1422
  ```
1035
1423
 
1036
- Then parsing the following inputs:
1424
+ Then parsing the command line inputs:
1037
1425
 
1038
1426
  ```ruby
1039
1427
  parse(%w[12 --bar baz=a QUX=b])
1040
1428
  ```
1041
1429
 
1042
- Would populate parameters:
1430
+ This would result in:
1043
1431
 
1044
1432
  ```ruby
1045
1433
  params[:foo] # => "12"
@@ -1048,59 +1436,111 @@ params[:baz] # => "a"
1048
1436
  params[:qux] # => "b"
1049
1437
  ```
1050
1438
 
1051
- The parsing is flexible and doesn't force any order for the parameters. Options can be inserted anywhere between positional or keyword arguments.
1439
+ The parser doesn't force any order for the parameters except for arguments.
1052
1440
 
1053
- It handles parsing of compacted shorthand options that start with a single dash. These need to be boolean options bar the last one that can accept argument. All these are valid:
1441
+ For example, reordering inputs for the previous parameter definitions:
1054
1442
 
1443
+ ```ruby
1444
+ parse(%w[12 QUX=b --bar baz=a])
1055
1445
  ```
1056
- -f
1057
- -fbq
1058
- -fbqs 12 # mixed with an argument
1446
+
1447
+ This would result in the same values:
1448
+
1449
+ ```ruby
1450
+ params[:foo] # => "12"
1451
+ params[:bar] # => true
1452
+ params[:baz] # => "a"
1453
+ params[:qux] # => "b"
1454
+ ```
1455
+
1456
+ The parser handles compact shorthand options that start with
1457
+ a single dash. These must be boolean options except for
1458
+ the last one that can accept an argument.
1459
+
1460
+ For example, passing three flags and an option with an argument to parse:
1461
+
1462
+ ```
1463
+ parse(%w[-f -b -q -s 12])
1464
+ ```
1465
+
1466
+ This is equivalent to parsing:
1467
+
1468
+ ```
1469
+ parse(%w[-fbqs 12])
1470
+ ```
1471
+
1472
+ Parameter parsing stops at the `--` terminator. The parser collects leftover
1473
+ inputs and makes them accessible with the [remaining](#272-remaining) method.
1474
+
1475
+ For example, given extra input after the terminator:
1476
+
1477
+ ```ruby
1478
+ parse(%w[12 baz=a QUX=b -- --fum])
1059
1479
  ```
1060
1480
 
1061
- Parameter parsing stops after the `--` terminator is found. The leftover inputs are collected and accessible via the `remaining` method.
1481
+ This would result in:
1482
+
1483
+ ```ruby
1484
+ params[:foo] # => 12
1485
+ params[:bar] # => false
1486
+ params[:baz] # => "a"
1487
+ params[:qux] # => "b"
1488
+ params.remaining # => ["--fum"]
1489
+ ```
1062
1490
 
1063
1491
  #### 2.6.1 :raise_on_parse_error
1064
1492
 
1065
- By default no parse errors are raised. Why? Users do not appreciate Ruby errors in their terminal output. Instead, parsing errors are made accessible on the `params` object with the [errors](#271-errors) method.
1493
+ The `parse` method doesn't raise any errors by default. Why? Displaying
1494
+ error backtraces in the terminal output may not be helpful for users.
1495
+ Instead, the parser collects any errors and exposes them through the
1496
+ [errors](#271-errors) method.
1066
1497
 
1067
- However, if you prefer to handle parsing errors yourself, you can do so with `:raise_on_parse_error` keyword:
1498
+ Use the `:raise_on_parse_error` keyword set to `true` to raise parsing errors:
1068
1499
 
1069
1500
  ```ruby
1070
1501
  parse(raise_on_parse_error: true)
1071
1502
  ```
1072
1503
 
1073
- Then in your code you may want to surround your `parse` call with a rescue clause:
1504
+ Parsing errors inherit from `TTY::Option::ParseError`.
1505
+
1506
+ For example, to catch parsing errors:
1074
1507
 
1075
1508
  ```ruby
1076
1509
  begin
1077
1510
  parse(raise_on_parse_error: true)
1078
1511
  rescue TTY::Option::ParseError => err
1079
- # do something here
1512
+ ...
1080
1513
  end
1081
1514
  ```
1082
1515
 
1083
1516
  #### 2.6.2 :check_invalid_params
1084
1517
 
1085
- Users can provide any input, including parameters you didn't expect and define.
1518
+ Users can provide any input, including parameters the parser
1519
+ didn't expect and define.
1086
1520
 
1087
- By default, when unknown parameter is found in the input, an `TTY::Option::InvalidParameter` error will be raised internally and collected in the `errors` list.
1521
+ When the parser finds an unknown input on the command line, it raises
1522
+ a `TTY::Option::InvalidParameter` error and adds it to the
1523
+ [errors](#271-errors) array.
1088
1524
 
1089
- If, on the other hand, you want to ignore unknown parameters and instead leave them alone during the parsing use the `:check_invalid_params` option like so:
1525
+ Use the `:check_invalid_params` keyword set to `false` to ignore unknown
1526
+ inputs during parsing:
1090
1527
 
1091
1528
  ```ruby
1092
1529
  parse(check_invalid_params: false)
1093
1530
  ```
1094
1531
 
1095
- This way all the unrecognized parameters will be collected into a [remaining](#272-remaining) list accessible on the `params` instance.
1532
+ This way, the parser will collect all the unrecognised inputs into the
1533
+ [remaining](#272-remaining) array.
1096
1534
 
1097
1535
  ### 2.7 params
1098
1536
 
1099
- Once all parameters are defined, they are accessible via the `params` instance method.
1537
+ All defined parameters are accessible from the `params` object.
1100
1538
 
1101
- The `params` behaves like a hash with an indifferent access. It doesn't distinguish between arguments, keywords or options. Each parameter needs to have a unique identifier.
1539
+ The `params` object behaves like a hash with indifferent access. It doesn't
1540
+ differentiate between arguments, keywords, options or environment variables.
1541
+ Because of that, each parameter needs to have a unique name.
1102
1542
 
1103
- For example, given a command with all parameter definitions:
1543
+ For example, given a command with all parameter types:
1104
1544
 
1105
1545
  ```ruby
1106
1546
  class Command
@@ -1110,7 +1550,9 @@ class Command
1110
1550
 
1111
1551
  keyword :bar
1112
1552
 
1113
- option :baz
1553
+ option :baz do
1554
+ long "--baz string"
1555
+ end
1114
1556
 
1115
1557
  env :qux
1116
1558
 
@@ -1123,17 +1565,22 @@ class Command
1123
1565
  end
1124
1566
  ```
1125
1567
 
1126
- Then parsing the command:
1568
+ And the following command line input:
1569
+
1570
+ ```
1571
+ a bar=b --baz c QUX=d
1572
+ ```
1573
+
1574
+ Then instantiating the command:
1127
1575
 
1128
1576
  ```ruby
1129
1577
  cmd = Command.new
1130
- cmd.parse
1131
1578
  ```
1132
1579
 
1133
- With the command-line input:
1580
+ And parsing command line input:
1134
1581
 
1135
- ```
1136
- a bar=b --baz c QUX=d
1582
+ ```ruby
1583
+ cmd.parse
1137
1584
  ```
1138
1585
 
1139
1586
  And running the command:
@@ -1142,7 +1589,7 @@ And running the command:
1142
1589
  cmd.run
1143
1590
  ```
1144
1591
 
1145
- Will output:
1592
+ This would result in the following output:
1146
1593
 
1147
1594
  ```
1148
1595
  abcd
@@ -1150,21 +1597,34 @@ abcd
1150
1597
 
1151
1598
  #### 2.7.1 errors
1152
1599
 
1153
- Only configuration errors are raised. The parsing errors are not raised by default. Instead any parse error is made available via the `errors` method on the `params` object:
1600
+ The `parse` method only raises configuration errors. The parsing errors are
1601
+ not raised by default. Instead, the `errors` method on the `params` object
1602
+ gives access to any parsing error.
1154
1603
 
1155
1604
  ```ruby
1156
- params.errors
1157
- # => AggregateErors
1158
- ````
1605
+ params.errors # => TTY::Option::AggregateErrors
1606
+ ```
1607
+
1608
+ The `errors` method returns an `TTY::Option::AggregateErrors` object that
1609
+ is an `Enumerable`.
1159
1610
 
1160
- The returned `AggregateErrors` object is an `Enumerable` that allows you to iterate over all of the errors.
1611
+ For example, to iterate over all the errors:
1612
+
1613
+ ```ruby
1614
+ params.errors.each do |error|
1615
+ ...
1616
+ end
1617
+ ```
1161
1618
 
1162
- It has also a convenience methods like:
1619
+ The `TTY::Option::AggregateErrors` object has the following
1620
+ convenience methods:
1163
1621
 
1164
- * `messages` - access all error messages as an array
1165
- * `summary` - a string of nicely formatted error messages ready to display in terminal
1622
+ * `messages` - an array of all error messages
1623
+ * `summary` - a string of formatted error messages ready to display
1624
+ in the terminal
1166
1625
 
1167
- For example, let's say we have an argument definition that requires at least 2 occurrences on the command line:
1626
+ For example, given an argument that needs to appear at least two times in
1627
+ the command line input:
1168
1628
 
1169
1629
  ```ruby
1170
1630
  argument :foo do
@@ -1172,28 +1632,40 @@ argument :foo do
1172
1632
  end
1173
1633
  ```
1174
1634
 
1175
- And only one argument is provided in the input. Then output summary:
1635
+ And parsing only one argument from the command line input:
1636
+
1637
+ ```ruby
1638
+ parse(%w[12])
1639
+ ```
1640
+
1641
+ Then printing errors summary:
1176
1642
 
1177
1643
  ```ruby
1178
1644
  puts params.errors.summary
1179
- ````
1645
+ ```
1180
1646
 
1181
- Would result in the following being printed:
1647
+ This would print the following error message:
1182
1648
 
1183
1649
  ```
1184
1650
  Error: argument 'foo' should appear at least 2 times but appeared 1 time
1185
1651
  ```
1186
1652
 
1187
- Let's change the previous example and add conversion to the mix:
1653
+ Adding integer conversion to the previous example:
1188
1654
 
1189
1655
  ```ruby
1190
1656
  argument :foo do
1191
1657
  arity at_least(2)
1192
1658
  convert :int
1193
1659
  end
1194
- ````
1660
+ ```
1661
+
1662
+ And given only one invalid argument to parse:
1663
+
1664
+ ```ruby
1665
+ parse(%w[zzz])
1666
+ ```
1195
1667
 
1196
- And provided only one argument string "zzz", the summary would be:
1668
+ The summary would be:
1197
1669
 
1198
1670
  ```
1199
1671
  Errors:
@@ -1201,133 +1673,163 @@ Errors:
1201
1673
  2) Cannot convert value of `zzz` into 'int' type for 'foo' argument
1202
1674
  ```
1203
1675
 
1204
- If, on the other hand, you prefer to raise errors, you can do so using the `:raise_on_parse_error` keyword:
1676
+ Use the [:raise_on_parse_error](#261-raise_on_parse_error) keyword to raise
1677
+ parsing errors on invalid input.
1678
+
1679
+ Consider using the [tty-exit](https://github.com/piotrmurach/tty-exit) gem
1680
+ for more expressive exit code reporting.
1681
+
1682
+ For example, the `TTY::Exit` module provides the `exit_with` method:
1205
1683
 
1206
1684
  ```ruby
1207
- parse(raise_on_parse_error: true)
1208
- ```
1685
+ class Command
1686
+ include TTY::Exit
1687
+ include TTY::Option
1209
1688
 
1210
- This way any attempt at parsing invalid input will raise to the terminal.
1689
+ def run
1690
+ if params.errors.any?
1691
+ exit_with(:usage_error, params.errors.summary)
1692
+ end
1693
+ ...
1694
+ end
1695
+ end
1696
+ ```
1211
1697
 
1212
1698
  #### 2.7.2 remaining
1213
1699
 
1214
- Users can provide any input, including parameters you didn't expect and define.
1215
-
1216
- By default, when unknown parameter is found in the input, an `TTY::Option::InvalidParameter` error will be raised internally and collected in the `errors` list.
1700
+ When the parser finds an unknown input on the command line, it raises
1701
+ a `TTY::Option::InvalidParameter` error and adds it to the
1702
+ [errors](#271-errors) array.
1217
1703
 
1218
- If, on the other hand, you want to ignore unknown parameters and instead leave them alone during the parsing use the `:check_invalid_params` option like so:
1704
+ Use the [:check_invalid_params](#262-check_invalid_params) keyword
1705
+ set to `false` to ignore unknown inputs during parsing:
1219
1706
 
1220
1707
  ```ruby
1221
- parse(check_invalid_params: true)
1708
+ parse(check_invalid_params: false)
1222
1709
  ```
1223
1710
 
1224
- This way all the unrecognized parameters will be collected into a list. You can access them on the `params` instance with the `remaining` method.
1711
+ This way, the parser will collect all the unrecognised inputs
1712
+ into an array. The `remaining` method on the `params` gives access
1713
+ to all invalid inputs.
1225
1714
 
1226
- For example, let's assume that user provided `--unknown` option that we didn't expect. Inspecting the `remaining` parameters, we would get:
1715
+ For example, given an unknown option to parse:
1227
1716
 
1228
1717
  ```ruby
1229
- params.remaining # => ["--unknown"]
1718
+ parse(%w[--unknown])
1230
1719
  ```
1231
1720
 
1232
- Any parameters after the `--` terminator will be left alone during the parsing process and collected into the `remaining` list. This is useful in situations when you want to pass parameters over to another command-line applications.
1233
-
1234
- #### 2.7.3 valid?
1235
-
1236
- Once parsing of the command-line input is done, you can check if all the conditions defined by the parameters are met with the `valid?` method.
1721
+ Then inspecting the `remaining` inputs:
1237
1722
 
1238
1723
  ```ruby
1239
- params.valid?
1724
+ params.remaining # => ["--unknown"]
1240
1725
  ```
1241
1726
 
1242
- You can use this to decide how to deal with parsing errors and what exit status to use.
1727
+ The parser leaves any inputs after the `--` terminator alone. Instead,
1728
+ it collects them into the remaining array. This is useful when passing
1729
+ inputs over to other command line applications.
1730
+
1731
+ #### 2.7.3 valid?
1732
+
1733
+ Use the `valid?` method to check that command line inputs meet all
1734
+ validation rules.
1243
1735
 
1244
- For example, you can decide to implement a command method like this:
1736
+ The `valid?` method is available on the `params` object:
1245
1737
 
1246
1738
  ```ruby
1247
- if params.valid?
1248
- # ... process params
1249
- else
1250
- puts params.errors.summary
1251
- exit
1252
- end
1739
+ params.valid? # => true
1253
1740
  ```
1254
1741
 
1255
- You can combine errors reporting with existing with the [tty-exit](https://github.com/piotrmurach/tty-exit) module.
1256
-
1257
- The `TTY::Exit` module exposes the `exit_with` method and can be used like this:
1742
+ Use the [errors](#271-errors) method to check for any errors and not only
1743
+ validation rules:
1258
1744
 
1259
1745
  ```ruby
1260
- class Command
1261
- include TTY::Exit
1262
- include TTY::Option
1263
-
1264
- def run
1265
- if params.valid?
1266
- # ... process params
1267
- else
1268
- exit_with(:usage_error, params.errors.summary)
1269
- end
1270
- end
1271
- end
1746
+ params.errors.any?
1272
1747
  ```
1273
1748
 
1274
1749
  ### 2.8 usage
1275
1750
 
1276
- The `usage` and its helper methods allow you to configure the `help` display to your liking. The `header`, `desc(ription)`, `example` and `footer` can be called many times. Each new call will create a new paragraph. If you wish to insert multiple lines inside a given paragraph separate arguments with a comma.
1751
+ The `usage` method accepts a block that configures the
1752
+ [help](#29-help) display.
1277
1753
 
1278
1754
  #### 2.8.1 header
1279
1755
 
1280
- To provide information above the banner explaining how to execute a program, use the `header` helper.
1756
+ Use the `header` setting to display information above the banner.
1757
+
1758
+ For example, to explain a program's purpose:
1281
1759
 
1282
1760
  ```ruby
1283
1761
  usage do
1284
- header "A command-line interface for foo service"
1762
+ header "A command line interface for foo service"
1285
1763
  end
1286
1764
  ```
1287
1765
 
1288
- Further, you can add more paragraphs as comma-separated arguments to `header` with an empty string to represent a new line:
1766
+ This would print:
1767
+
1768
+ ```
1769
+ A command line interface for foo service
1770
+
1771
+ Usage: foo [OPTIONS]
1772
+ ```
1773
+
1774
+ The `header` setting accepts many arguments, each representing a single
1775
+ paragraph. An empty string displays as a new line.
1776
+
1777
+ For example, to create an introduction with two paragraphs separated by
1778
+ an empty line:
1289
1779
 
1290
1780
  ```ruby
1291
1781
  usage do
1292
- header "A command-line interface for foo service",
1782
+ header "A command line interface for foo service",
1293
1783
  "",
1294
1784
  "Access and retrieve data from foo service"
1295
1785
  end
1296
1786
  ```
1297
1787
 
1298
- Alternatively, you can add paragraphs calling `header` multiple times:
1788
+ Or, add two paragraphs using the `header` setting twice:
1299
1789
 
1300
1790
  ```ruby
1301
1791
  usage do
1302
- header "A command-line interface for foo service"
1792
+ header "A command line interface for foo service"
1303
1793
 
1304
1794
  header "Access and retrieve data from foo service"
1305
1795
  end
1306
1796
  ```
1307
1797
 
1798
+ Both would result in the same output:
1799
+
1800
+ ```
1801
+ A command line interface for foo service
1802
+
1803
+ Access and retrieve data from foo service
1804
+
1805
+ Usage: foo [OPTIONS]
1806
+ ```
1807
+
1308
1808
  #### 2.8.2 program
1309
1809
 
1310
- By default the program name is inferred for you from the executable file name.
1810
+ The `program` setting uses an executable file name to generate a program
1811
+ name by default.
1311
1812
 
1312
- You can override the default name using the `program` helper.
1813
+ For example, to override the default name:
1313
1814
 
1314
1815
  ```ruby
1315
1816
  usage do
1316
1817
  program "custom-name"
1317
1818
  end
1318
- ````
1819
+ ```
1319
1820
 
1320
- Then the program name will be used in the banner:
1821
+ Then usage banner will display a custom program name:
1321
1822
 
1322
- ```bash
1823
+ ```
1323
1824
  Usage: custom-name
1324
1825
  ```
1325
1826
 
1326
1827
  #### 2.8.3 command
1327
1828
 
1328
- By default the command name is inferred from the class name.
1829
+ The `command` setting uses a class name to generate a command name by default.
1830
+ It converts a class name into a dash case.
1329
1831
 
1330
- For example, based on the following:
1832
+ For example, given the following command class name:
1331
1833
 
1332
1834
  ```ruby
1333
1835
  class NetworkCreate
@@ -1335,111 +1837,187 @@ class NetworkCreate
1335
1837
  end
1336
1838
  ```
1337
1839
 
1338
- The command name will become `network-create`. To change this use the `command` and `commands` helpers:
1840
+ The command name would become `network-create`.
1841
+
1842
+ Use the `command` or `commands` setting to change the default command name.
1843
+
1844
+ For example, to change the previous class's default command name:
1339
1845
 
1340
1846
  ```ruby
1341
1847
  class NetworkCreate
1342
1848
  include TTY::Option
1343
1849
 
1344
1850
  usage do
1345
- commands "network", "create"
1851
+ command "net-create"
1852
+ end
1853
+ end
1854
+ ```
1855
+
1856
+ The usage banner would be:
1857
+
1858
+ ```
1859
+ Usage: program net-create
1860
+ ```
1861
+
1862
+ Use the `commands` setting for naming a subcommand.
1863
+
1864
+ For example, to add `create` command as a subcommand:
1865
+
1866
+ ```ruby
1867
+ module Network
1868
+ class Create
1869
+ include TTY::Option
1870
+
1871
+ usage do
1872
+ commands "network", "create"
1873
+ end
1346
1874
  end
1347
1875
  end
1348
- ````
1876
+ ```
1349
1877
 
1350
- This will result in the following usage information:
1878
+ This will result in the following usage banner:
1351
1879
 
1352
1880
  ```
1353
1881
  Usage: program network create
1354
1882
  ```
1355
1883
 
1356
- If you don't wish to infer the command name use the `no_command` method:
1884
+ Use the `no_command` setting to skip having a command name:
1357
1885
 
1358
1886
  ```ruby
1359
1887
  usage do
1360
1888
  no_command
1361
1889
  end
1362
- ````
1890
+ ```
1363
1891
 
1364
- #### 2.8.4 banner
1892
+ This will display only the program name:
1893
+
1894
+ ```
1895
+ Usage: program
1896
+ ```
1365
1897
 
1366
- The usage information of how to use a program is displayed right after header. If no header is specified, it will be displayed first.
1898
+ #### 2.8.4 banner
1367
1899
 
1368
- This information is handled by the `banner` helper. By default, it will use the parameter definitions to generate usage information.
1900
+ The `banner` setting combines program, command and parameter names
1901
+ to generate usage banner.
1369
1902
 
1370
- For example, given the following declarations:
1903
+ For example, given the following usage and parameter definitions:
1371
1904
 
1372
1905
  ```ruby
1373
1906
  usage do
1374
- program :foo
1907
+ program "prog"
1375
1908
 
1376
- command :bar
1909
+ command "cmd"
1377
1910
  end
1378
1911
 
1379
- argument :baz
1912
+ argument :foo
1380
1913
 
1381
- keyword :qux do
1382
- convert :uri
1383
- end
1914
+ keyword :bar
1384
1915
 
1385
- option :fum
1916
+ option :baz
1917
+
1918
+ env :qux
1386
1919
  ```
1387
1920
 
1388
- The generated usage information will be:
1921
+ Then usage banner would print as follows:
1389
1922
 
1390
- ```bash
1391
- Usage: foo bar [OPTIONS] BAZ [QUX=URI]
1923
+ ```
1924
+ Usage: prog cmd [OPTIONS] [ENVIRONMENT] FOO [BAR=BAR]
1392
1925
  ```
1393
1926
 
1394
- If you want to configure how arguments are displayed specify [2.8.2 :param_display](#282-param_display) setting.
1927
+ The [help](#29-help) generator displays the usage banner first
1928
+ unless a [header](#281-header) is set.
1395
1929
 
1396
- You can also change completely how to the banner is displayed:
1930
+ Use the `banner` setting to create a custom usage display.
1931
+
1932
+ For example, to change the parameters format:
1397
1933
 
1398
1934
  ```ruby
1399
1935
  usage do
1400
- program "foo"
1936
+ program "prog"
1937
+
1938
+ command "cmd"
1401
1939
 
1402
- banner "Usage: #{program} BAR BAZ"
1940
+ banner "Usage: #{program} #{command.first} <opts> <envs> foo [bar=bar]"
1403
1941
  end
1404
1942
  ```
1405
1943
 
1406
- #### 2.8.5 desc(ription)
1944
+ This would display as:
1945
+
1946
+ ```
1947
+ Usage: prog cmd <opts> <envs> foo [bar=bar]
1948
+ ```
1949
+
1950
+ Use the [:param_display](#294-param_display) setting to change the banner
1951
+ parameters format.
1407
1952
 
1408
- The description is placed between usage information and the parameters and given with `desc` or `description` helpers.
1953
+ #### 2.8.5 description
1409
1954
 
1410
- The `desc` helper accepts multiple strings that will be displayed on separate lines.
1955
+ Use `description` or `desc` setting to display information right after
1956
+ the usage banner.
1957
+
1958
+ For example, to give extra information:
1411
1959
 
1412
1960
  ```ruby
1413
1961
  usage do
1414
- desc "Some description", "on multiline"
1962
+ desc "A description for foo service"
1415
1963
  end
1416
1964
  ```
1417
1965
 
1418
- This will result in the following help output:
1966
+ This would print:
1419
1967
 
1420
1968
  ```
1421
- Some description
1422
- on multiline
1969
+ Usage: foo [OPTIONS]
1970
+
1971
+ A description for foo service
1972
+ ```
1973
+
1974
+ The `desc` setting accepts many arguments, each representing a single
1975
+ paragraph. An empty string displays as a new line.
1976
+
1977
+ For example, to create a description with two paragraphs separated by
1978
+ an empty line:
1979
+
1980
+ ```ruby
1981
+ usage do
1982
+ desc "A description for foo service",
1983
+ "",
1984
+ "Learn more about foo service\nby reading tutorials"
1985
+ end
1423
1986
  ```
1424
1987
 
1425
- The `desc` helper can be called multiple times to build an examples section:
1988
+ Or, add two paragraphs using the `desc` setting twice:
1426
1989
 
1427
1990
  ```ruby
1428
1991
  usage do
1429
- desc "Some description", "on multiline"
1992
+ desc "A description for foo service",
1430
1993
 
1431
1994
  desc <<~EOS
1432
- Another description
1433
- on multiline
1995
+ Learn more about foo service
1996
+ by reading tutorials
1434
1997
  EOS
1435
1998
  end
1436
1999
  ```
1437
2000
 
1438
- #### 2.8.6 example(s)
2001
+ Both would result in the same output:
1439
2002
 
1440
- To add usage examples section to the help information use the `example` or `examples` methods.
2003
+ ```
2004
+ Usage: foo [OPTIONS]
2005
+
2006
+ A description for foo service
2007
+
2008
+ Learn more about foo service
2009
+ by reading tutorials
2010
+ ```
1441
2011
 
1442
- The `example` helper accepts multiple strings that will be displayed on separate lines. For instance, the following class will add a single example:
2012
+ #### 2.8.6 example
2013
+
2014
+ Use the `example` or `examples` setting to add a usage examples section
2015
+ to the help display.
2016
+
2017
+ The `example` setting accepts many arguments, each representing a single
2018
+ paragraph. An empty string displays as a new line.
2019
+
2020
+ For instance, to create an example usage displayed on two lines:
1443
2021
 
1444
2022
  ```ruby
1445
2023
  usage do
@@ -1456,7 +2034,8 @@ Examples:
1456
2034
  $ foo bar
1457
2035
  ```
1458
2036
 
1459
- The `example` helper can be called multiple times to build an examples section:
2037
+ Or, add two examples using the `example` setting twice:
2038
+
1460
2039
 
1461
2040
  ```ruby
1462
2041
  usage do
@@ -1470,7 +2049,7 @@ usage do
1470
2049
  end
1471
2050
  ```
1472
2051
 
1473
- The usage help will contain the following:
2052
+ The examples section would display the following:
1474
2053
 
1475
2054
  ```
1476
2055
  Examples:
@@ -1483,39 +2062,68 @@ Examples:
1483
2062
 
1484
2063
  #### 2.8.7 footer
1485
2064
 
1486
- To provide information after all information in the usage help, use the `footer` helper.
2065
+ Use the `footer` setting to display text after all information
2066
+ in the usage help.
2067
+
2068
+ For example, to reference further help:
1487
2069
 
1488
2070
  ```ruby
1489
2071
  usage do
1490
- footer "Run a command followed by --help to see more info"
2072
+ footer "Run a command followed by --help to see more info."
1491
2073
  end
1492
2074
  ```
1493
2075
 
1494
- Further, you can add more paragraphs as comma-separated arguments to `footer` with an empty string to represent a new line:
2076
+ This would print as follows:
2077
+
2078
+ ```
2079
+ Usage: foo [OPTIONS]
2080
+
2081
+ Run a command followed by --help to see more info.
2082
+ ```
2083
+
2084
+ The `footer` setting accepts many arguments, each representing a single
2085
+ paragraph. An empty string displays as a new line.
2086
+
2087
+ For example, to display further help with two paragraphs separated by
2088
+ an empty line:
1495
2089
 
1496
2090
  ```ruby
1497
2091
  usage do
1498
- footer "Run a command followed by --help to see more info",
2092
+ footer "Run a command followed by --help to see more info.",
1499
2093
  "",
1500
- "Options marked with (...) can be given more than once"
2094
+ "Report bugs to the mailing list."
1501
2095
  end
1502
2096
  ```
1503
2097
 
1504
- Alternatively, you can add paragraphs calling `footer` multiple times:
2098
+ Or, add two paragraphs using the `footer` setting twice:
1505
2099
 
1506
2100
  ```ruby
1507
2101
  usage do
1508
- footer "Run a command followed by --help to see more info"
2102
+ footer "Run a command followed by --help to see more info."
1509
2103
 
1510
- footer "Options marked with (...) can be given more than once"
2104
+ footer "Report bugs to the mailing list."
1511
2105
  end
1512
2106
  ```
1513
2107
 
2108
+ Both would result in the same output:
2109
+
2110
+ ```
2111
+ Usage: foo [OPTIONS]
2112
+
2113
+ Run a command followed by --help to see more info.
2114
+
2115
+ Report bugs to the mailing list.
2116
+ ```
2117
+
1514
2118
  ### 2.9 help
1515
2119
 
1516
- With the `help` instance method you can generate usage information from the defined parameters and the usage. The [usage](#28-usage) describes how to add different sections to the help display.
2120
+ Use the `help` method to generate usage information about defined parameters.
2121
+
2122
+ The [usage](#28-usage) describes how to add different sections to the
2123
+ help display.
1517
2124
 
1518
- Let's assume you have the following command with a run method that prints help:
2125
+ For example, given the following command class definition with
2126
+ a `run` method that prints help:
1519
2127
 
1520
2128
 
1521
2129
  ```ruby
@@ -1523,16 +2131,18 @@ class Command
1523
2131
  include TTY::Option
1524
2132
 
1525
2133
  usage do
1526
- program "foobar",
1527
- header "foobar CLI"
1528
- desc "Some foobar description"
1529
- example "Some example"
1530
- footer "Run --help to see more info"
2134
+ program "foobar"
2135
+ no_command
2136
+ header "foobar CLI"
2137
+ desc "CLI description"
2138
+ example "Example usage"
2139
+ footer "Run --help to see more info"
1531
2140
  end
1532
2141
 
1533
- argument :bar, desc: "Some argument description"
1534
- keyword :baz, desc: "Some keyword description"
1535
- env :fum, desc: "Some env description"
2142
+ argument :foo, desc: "Argument description"
2143
+ keyword :bar, desc: "Keyword description"
2144
+ option :baz, desc: "Option description"
2145
+ env :qux, desc: "Environment description"
1536
2146
 
1537
2147
  flag :help do
1538
2148
  short "-h"
@@ -1557,38 +2167,42 @@ cmd.parse(%w[--help])
1557
2167
  cmd.run
1558
2168
  ```
1559
2169
 
1560
- Will produce:
2170
+ This would result in the following help display:
1561
2171
 
1562
2172
  ```
1563
2173
  foobar CLI
1564
2174
 
1565
- Usage: foobar [OPTIONS] [ENVIRONMENT] BAR [BAZ=BAZ]
2175
+ Usage: foobar [OPTIONS] [ENVIRONMENT] FOO [BAR=BAR]
1566
2176
 
1567
- Some foobar description
2177
+ CLI description
1568
2178
 
1569
2179
  Arguments:
1570
- BAR Some argument description
2180
+ FOO Argument description
1571
2181
 
1572
2182
  Keywords:
1573
- BAZ=BAZ Some keyword description
2183
+ BAR=BAR Keyword description
1574
2184
 
1575
2185
  Options:
1576
- -h, --help Print usage
2186
+ --baz Option description
2187
+ -h, --help Print usage
1577
2188
 
1578
- Envrionment:
1579
- FUM Some env description
2189
+ Environment:
2190
+ QUX Environment description
1580
2191
 
1581
2192
  Examples:
1582
- Some example
2193
+ Example usage
1583
2194
 
1584
2195
  Run --help to see more info
1585
2196
  ```
1586
2197
 
1587
2198
  #### 2.9.1 sections
1588
2199
 
1589
- It is possible to change the usage content by passing a block to `help`. The `help` method yields an object that contains all the sections and provides a hash-like access to each of its sections.
2200
+ Pass a block to the `help` method to change generated usage information.
2201
+ The block accepts a single argument, a `TTY::Option::Sections` object.
2202
+ This object provides hash-like access to each named part of the help display.
1590
2203
 
1591
- The following are the names for all supported sections:
2204
+ The following are the names of all supported sections ordered by help display
2205
+ from top to bottom:
1592
2206
 
1593
2207
  * `:header`
1594
2208
  * `:banner`
@@ -1597,41 +2211,94 @@ The following are the names for all supported sections:
1597
2211
  * `:keywords`
1598
2212
  * `:options`
1599
2213
  * `:environments`
1600
- * `:exmaples`
2214
+ * `:examples`
1601
2215
  * `:footer`
1602
2216
 
1603
- You can use `add_before`, `add_after`, `delete` and `replace` to modify currently existing sections or add new ones.
2217
+ Accessing a named section returns a `TTY::Option::Section` object
2218
+ with `name` and `content` methods.
1604
2219
 
1605
- For example, to remove a header section do:
2220
+ For example, to access the arguments section content:
1606
2221
 
1607
2222
  ```ruby
1608
2223
  help do |sections|
1609
- sections.delete :header
2224
+ sections[:arguments].content # => "\nArguments:\n FOO Argument description"
1610
2225
  end
1611
2226
  ```
1612
2227
 
1613
- To insert a new section after `:arguments` called `:commands` do:
2228
+ To add a new section, use the `add_after` and `add_before` methods. These
2229
+ methods accept three arguments. The first argument is the section name
2230
+ to add after or before. The second argument is a new section name,
2231
+ and the last is content to add.
2232
+
2233
+ For example, to insert a new commands section after the description:
1614
2234
 
1615
2235
  ```ruby
1616
2236
  help do |sections|
1617
- sections.add_after :arguments, :commands,
1618
- "\nCommands:\n create A command description"
2237
+ sections.add_after :description, :commands, <<~EOS.chomp
2238
+
2239
+ Commands:
2240
+ create Create command description
2241
+ delete Delete command description
2242
+ EOS
2243
+ end
2244
+ ```
2245
+
2246
+ Given the following usage and parameter definition:
2247
+
2248
+ ```ruby
2249
+ usage do
2250
+ program "prog"
2251
+
2252
+ command "cmd"
2253
+
2254
+ desc "Program description"
2255
+ end
2256
+
2257
+ argument :foo do
2258
+ desc "Foo argument description"
1619
2259
  end
1620
2260
  ```
1621
2261
 
1622
- To replace a section's content use `replace`:
2262
+ The help display would be:
2263
+
2264
+ ```
2265
+ Usage: prog cmd FOO
2266
+
2267
+ Program description
2268
+
2269
+ Commands:
2270
+ create Create command description
2271
+ delete Delete command description
2272
+
2273
+ Arguments:
2274
+ FOO Argument description
2275
+ ```
2276
+
2277
+ Use `delete` and `replace` methods to change existing sections.
2278
+
2279
+ For example, to remove a header section:
1623
2280
 
1624
2281
  ```ruby
1625
2282
  help do |sections|
1626
- sections.replace :footer, "\nGoodbye"
2283
+ sections.delete :header
2284
+ end
2285
+ ```
2286
+
2287
+ Or, to replace the content of a footer section:
2288
+
2289
+ ```ruby
2290
+ help do |sections|
2291
+ sections.replace :footer, "\nReport bugs to the mailing list."
1627
2292
  end
1628
2293
  ```
1629
2294
 
1630
2295
  #### 2.9.2 :indent
1631
2296
 
1632
- By default has not indentation for any of the sections bar parameters.
2297
+ The help output has no indentation except for displaying parameters by default.
2298
+
2299
+ Use the `:indent` keyword to change the indentation of the help display.
1633
2300
 
1634
- To change the indentation for the entire usage information use `:indent` keyword:
2301
+ For example, to indent help display by two spaces:
1635
2302
 
1636
2303
  ```ruby
1637
2304
  help(indent: 2)
@@ -1639,58 +2306,91 @@ help(indent: 2)
1639
2306
 
1640
2307
  #### 2.9.3 :order
1641
2308
 
1642
- All parameters are alphabetically ordered in their respective sections. To change this default behaviour use the `:order` keyword when invoking `help`.
2309
+ The help generator orders parameters alphabetically within
2310
+ each section by default.
2311
+
2312
+ Use the `:order` keyword to change the default ordering.
2313
+
2314
+ The `:order` expects a `Proc` object as a value. The `Proc` accepts
2315
+ a single argument, an array of parameters within a section.
1643
2316
 
1644
- The `:order` expects a `Proc` object. For example, to remove any ordering and preserve the parameter declaration order do:
2317
+ For example, to preserve the parameter definition order:
1645
2318
 
1646
2319
  ```ruby
1647
2320
  help(order: ->(params) { params })
1648
- ````
2321
+ ```
1649
2322
 
1650
2323
  #### 2.9.4 :param_display
1651
2324
 
1652
- By default banner positional and keyword arguments are displayed with all letters uppercased.
2325
+ The usage banner displays positional and keyword arguments
2326
+ in uppercase letters by default.
1653
2327
 
1654
- For example, given the following parameter declarations:
2328
+ For example, given the following parameter definitions:
1655
2329
 
1656
2330
  ```ruby
1657
- program "run"
2331
+ usage do
2332
+ program "prog"
2333
+ end
1658
2334
 
1659
- argument :foo
2335
+ argument :foo, desc: "Argument description"
1660
2336
 
1661
- keyword :bar do
1662
- required
1663
- convert :uri
1664
- end
2337
+ keyword :bar, desc: "Keyword description"
1665
2338
 
1666
- option :baz
2339
+ option :baz, desc: "Option description"
2340
+
2341
+ env :qux, desc: "Environment description"
1667
2342
  ```
1668
2343
 
1669
- The banner output would be as follows:
2344
+ The usage banner would print as follows:
1670
2345
 
1671
- ```bash
1672
- Usage: run [OPTIONS] FOO BAR=URI
2346
+ ```
2347
+ Usage: prog [OPTIONS] [ENVIRONMENT] FOO [BAR=BAR]
1673
2348
  ```
1674
2349
 
1675
- To change the banner parameter display use `:param_display` keyword.
2350
+ Use the `:param_display` keyword to change the banner parameter formatting.
1676
2351
 
1677
- For example, to lowercase and surround your parameters with `< >` brackets do:
2352
+ The `:param_display` expects a `Proc` object as a value. The `Proc` accepts
2353
+ a single argument, a parameter name within a section.
2354
+
2355
+ For example, to lowercase and surround parameters with `<` and `>` brackets:
1678
2356
 
1679
2357
  ```ruby
1680
- help(param_display: ->(str) { "<#{str.downcase}>" })
2358
+ help(param_display: ->(param) { "<#{param.downcase}>" })
1681
2359
  ```
1682
2360
 
1683
- This will produce the following output:
2361
+ This would result in the following usage banner and parameter sections:
1684
2362
 
1685
2363
  ```
1686
- Usage: run [<options>] <foo> <bar>=<uri>
2364
+ Usage: prog [<options>] [<environment>] <foo> [<bar>=<bar>]
2365
+
2366
+ Arguments:
2367
+ <foo> Argument description
2368
+
2369
+ Keywords:
2370
+ <bar>=<bar> Keyword description
2371
+
2372
+ Options:
2373
+ --baz Option description
2374
+
2375
+ Environment:
2376
+ QUX Environment description
1687
2377
  ```
1688
2378
 
1689
2379
  #### 2.9.5 :width
1690
2380
 
1691
- By default the help information is wrapped at `80` columns. If this is not what you want you can change it with `:width` keyword.
2381
+ The help generator wraps content at the width of `80` columns by default.
2382
+
2383
+ Use the `:width` keyword to change it, for example, to `120` columns:
2384
+
2385
+ ```ruby
2386
+ help(width: 120)
2387
+ ```
2388
+
2389
+ Use the [tty-screen](https://github.com/piotrmurach/tty-screen) gem
2390
+ to change the help display based on terminal width.
1692
2391
 
1693
- For example, to change the help to always take up all the terminal columns consider using [tty-screen](https://github.com/piotrmurach/tty-screen):
2392
+ For example, to expand the help display to the full width of
2393
+ the terminal window:
1694
2394
 
1695
2395
  ```ruby
1696
2396
  help(width: TTY::Screen.width)
@@ -1698,21 +2398,33 @@ help(width: TTY::Screen.width)
1698
2398
 
1699
2399
  ## Development
1700
2400
 
1701
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
2401
+ After checking out the repo, run `bin/setup` to install dependencies.
2402
+ Then, run `rake spec` to run the tests. You can also run `bin/console`
2403
+ for an interactive prompt that will allow you to experiment.
1702
2404
 
1703
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
2405
+ To install this gem onto your local machine, run `bundle exec rake install`.
2406
+ To release a new version, update the version number in `version.rb`, and then
2407
+ run `bundle exec rake release`, which will create a git tag for the version,
2408
+ push git commits and tags, and push the `.gem` file to
2409
+ [rubygems.org](https://rubygems.org).
1704
2410
 
1705
2411
  ## Contributing
1706
2412
 
1707
- Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/tty-option. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/piotrmurach/tty-option/blob/master/CODE_OF_CONDUCT.md).
2413
+ Bug reports and pull requests are welcome on GitHub at
2414
+ https://github.com/piotrmurach/tty-option. This project is intended to be
2415
+ a safe, welcoming space for collaboration, and contributors are expected
2416
+ to adhere to the [code of conduct](https://github.com/piotrmurach/tty-option/blob/master/CODE_OF_CONDUCT.md).
1708
2417
 
1709
2418
  ## License
1710
2419
 
1711
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
2420
+ The gem is available as open source under the terms of the
2421
+ [MIT License](https://opensource.org/licenses/MIT).
1712
2422
 
1713
2423
  ## Code of Conduct
1714
2424
 
1715
- Everyone interacting in the TTY::Option project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/tty-option/blob/master/CODE_OF_CONDUCT.md).
2425
+ Everyone interacting in the TTY::Option project's codebases, issue trackers,
2426
+ chat rooms and mailing lists is expected to follow the
2427
+ [code of conduct](https://github.com/piotrmurach/tty-option/blob/master/CODE_OF_CONDUCT.md).
1716
2428
 
1717
2429
  ## Copyright
1718
2430