usage-lib 7.1.1

Library for working with usage specs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
{%- if cmd.before_help_long %}{{ cmd.before_help_long | terminal_wrap(width=terminal_width) }}

{% elif cmd.before_help %}{{ cmd.before_help | terminal_wrap(width=terminal_width) }}

{% elif root and spec.before_help_long %}{{ spec.before_help_long | terminal_wrap(width=terminal_width) }}

{% elif root and spec.before_help %}{{ spec.before_help | terminal_wrap(width=terminal_width) }}

{% endif -%}
{%- if root %}
{%- if spec.name and spec.version %}{{ spec.name }} {{ spec.version }}
{% elif spec.version %}{{ spec.bin }} {{ spec.version }}
{% endif -%}
{%- if spec.about_long %}{{ spec.about_long | terminal_wrap(width=terminal_width) }}

{% elif spec.about %}{{ spec.about | terminal_wrap(width=terminal_width) }}

{% endif -%}
{%- else -%}
{%- if cmd.help_long %}{{ cmd.help_long | terminal_wrap(width=terminal_width) }}

{% elif cmd.help %}{{ cmd.help | terminal_wrap(width=terminal_width) }}

{% endif -%}
{%- endif -%}
{%- if cmd.deprecated or cmd.deprecated_warn_at or cmd.deprecated_remove_at %}
{{ cmd | terminal_deprecation(width=terminal_width) }}

{%- endif -%}{{ mark_usage }}
{%- if cmd.flatten_help and cmd.flattened_usage %}
{%- for usage in cmd.flattened_usage %}
{% if loop.first %}Usage: {% else %}       {% endif %}{{ (spec.bin ~ " " ~ usage) | trim }}
{%- endfor %}
{%- else -%}
Usage: {{ (spec.bin ~ " " ~ cmd.usage) | trim }}
{%- endif %}{{ mark_commands }}

{%- if cmd.subcommands and not cmd.flatten_help %}
{%- set next_line_help = cmd.next_line_help %}
{%- for group in cmd.subcommand_groups %}

{{ group.heading | default(value=cmd.subcommand_help_heading | default(value="Commands")) }}:
{%- if group.help_rendered %}
  {{ group.help_rendered | indent(width=2) }}
{% endif %}
{%- for cmd in group.items %}
{%- if cmd.help_rendered and not next_line_help %}
  {{ cmd.name | ljust(width=cmd.usage_col_width) }}  {{ cmd.help_rendered }}
{%- elif cmd.row %}
  {{ cmd.name }}
{{ cmd.row }}
{%- else %}
  {{ cmd.name }}
{%- endif %}
{%- endfor %}
{%- if not group.heading and help_row %}
{{ help_row }}
{%- endif %}
{%- endfor %}
{%- endif %}{{ mark_args }}{% if not arg_has_ungrouped %}{{ mark_grouped_args }}{% endif %}

{%- for group in cmd.arg_groups %}
{%- if group.heading and arg_has_ungrouped and loop.index0 == 1 %}{{ mark_grouped_args }}{% endif %}

{{ group.heading | default(value="Arguments") }}:
{%- if group.help_rendered %}
  {{ group.help_rendered | indent(width=2) }}
{% endif %}
{%- for arg in group.items %}
{%- if cmd.next_line_help %}
  {{ arg.usage | trim }}
{%- if arg.row %}
{{ arg.row }}
{%- endif %}
{%- elif arg.help_rendered %}
  {{ arg.usage | ljust(width=arg.usage_col_width) }}  {{ arg.help_rendered }}
{%- if arg.help_is_multiline %}

{%- endif %}
{%- elif arg.row %}
  {{ arg.usage | trim }}
{{ arg.row }}
{%- else %}
  {{ arg.usage | trim }}
{%- set help = arg.help_long | default(value=arg.help | default(value='')) %}
{%- if help %}
{{ help | terminal_annotation(indent="    ", width=terminal_width) }}
{%- endif %}
{%- endif %}
{%- if arg.admonitions %}
{%- for admonition in arg.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.choices %}
{{ arg.choices.choices | terminal_annotation(label="[possible values: ", suffix="]", indent=arg.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.env %}
{{ arg.choices.env | terminal_annotation(label="[choices env: ", suffix="]", indent=arg.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.run %}
{{ arg.choices.run | terminal_annotation(label="[possible values: output of `", suffix="`]", indent=arg.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_env and arg.env %}
{{ arg.env | terminal_annotation(label="[env: ", suffix="]", indent=arg.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_env %}{% for env in arg.env_fallback %}
{{ env | terminal_annotation(label="[env fallback: ", suffix="]", indent=arg.ann_indent, width=terminal_width) }}
{%- endfor %}{% for env in arg.deprecated_env %}
{{ env | terminal_annotation(label="[deprecated env: ", suffix="]", indent=arg.ann_indent, width=terminal_width) }}
{%- endfor %}{%- endif %}
{%- if not arg.hide_default_value and arg.default %}
{{ arg.default | terminal_annotation(label="(default: ", suffix=")", indent=arg.ann_indent, width=terminal_width) }}
{%- endif %}
{%- endfor %}
{%- endfor %}{% if arg_has_ungrouped and not arg_has_grouped %}{{ mark_grouped_args }}{% endif %}{{ mark_flags }}{% if not flag_has_ungrouped %}{{ mark_grouped_flags }}{% endif %}

{%- for group in cmd.flag_groups %}
{%- if group.heading and flag_has_ungrouped and loop.index0 == 1 %}{{ mark_grouped_flags }}{% endif %}

{{ group.heading | default(value="Flags") }}:
{%- if group.help_rendered %}
  {{ group.help_rendered | indent(width=2) }}
{% endif %}
{%- for flag in group.items %}
{%- if cmd.next_line_help %}
  {{ flag.display_usage }}
{%- if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
{%- if flag.row %}
{{ flag.row }}
{%- endif %}
{%- elif flag.help_rendered %}
  {{ flag.display_usage | ljust(width=flag.usage_col_width) }}  {{ flag.help_rendered }}
{%- if flag.help_is_multiline %}

{%- endif %}
{%- elif flag.row %}
  {{ flag.display_usage }}
{%- if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
{{ flag.row }}
{%- else %}
  {{ flag.display_usage }}
{%- if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
{%- set help = flag.help_long | default(value=flag.help | default(value='')) %}
{%- if help %}
{{ help | terminal_annotation(indent="    ", width=terminal_width) }}
{%- endif %}
{%- endif %}
{%- if flag.admonitions %}
{%- for admonition in flag.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if flag.arg and flag.arg.admonitions %}
{%- for admonition in flag.arg.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %}
{{ flag.arg.choices.choices | terminal_annotation(label="[possible values: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %}
{{ flag.arg.choices.env | terminal_annotation(label="[choices env: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.run %}
{{ flag.arg.choices.run | terminal_annotation(label="[possible values: output of `", suffix="`]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_env and flag.env %}
{{ flag.env | terminal_annotation(label="[env: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %}
{{ env | terminal_annotation(label="[env fallback: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endfor %}{% for env in flag.deprecated_env %}
{{ env | terminal_annotation(label="[deprecated env: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %}
{{ flag.default | terminal_annotation(label="(default: ", suffix=")", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if flag.deprecated or flag.deprecated_warn_at or flag.deprecated_remove_at %}
{{ flag | terminal_deprecation(indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- endfor %}
{%- endfor %}{% if flag_has_ungrouped and not flag_has_grouped %}{{ mark_grouped_flags }}{% endif %}{{ mark_global_flags }}

{%- if global_flags %}

Global flags:
{%- for flag in global_flags %}
{%- if cmd.next_line_help %}
  {{ flag.display_usage }}
{%- if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
{%- if flag.row %}
{{ flag.row }}
{%- endif %}
{%- elif flag.help_rendered %}
  {{ flag.display_usage | ljust(width=flag.usage_col_width) }}  {{ flag.help_rendered }}
{%- if flag.help_is_multiline %}

{%- endif %}
{%- elif flag.row %}
  {{ flag.display_usage }}
{%- if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
{{ flag.row }}
{%- else %}
  {{ flag.display_usage }}
{%- if flag.aliases %}  [aliases: {{ flag.aliases | join(sep=", ") }}]{% endif %}
{%- set help = flag.help_long | default(value=flag.help | default(value='')) %}
{%- if help %}
{{ help | terminal_annotation(indent="    ", width=terminal_width) }}
{%- endif %}
{%- endif %}
{%- if flag.admonitions %}
{%- for admonition in flag.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if flag.arg and flag.arg.admonitions %}
{%- for admonition in flag.arg.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %}
{{ flag.arg.choices.choices | terminal_annotation(label="[possible values: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %}
{{ flag.arg.choices.env | terminal_annotation(label="[choices env: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.run %}
{{ flag.arg.choices.run | terminal_annotation(label="[possible values: output of `", suffix="`]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_env and flag.env %}
{{ flag.env | terminal_annotation(label="[env: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %}
{{ env | terminal_annotation(label="[env fallback: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endfor %}{% for env in flag.deprecated_env %}
{{ env | terminal_annotation(label="[deprecated env: ", suffix="]", indent=flag.ann_indent, width=terminal_width) }}
{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %}
{{ flag.default | terminal_annotation(label="(default: ", suffix=")", indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- if flag.deprecated or flag.deprecated_warn_at or flag.deprecated_remove_at %}
{{ flag | terminal_deprecation(indent=flag.ann_indent, width=terminal_width) }}
{%- endif %}
{%- endfor %}
{%- endif %}{{ mark_flattened }}

{%- if cmd.flatten_help %}
{%- for sub in cmd.flattened_subcommands %}

{{ sub.full_cmd | join(sep=" ") }}:
{%- set about = sub.help_long | default(value=sub.help | default(value='')) %}
{%- if about %}
{{ about | terminal_wrap(width=terminal_width) }}
{%- endif %}
{%- if sub.deprecated or sub.deprecated_warn_at or sub.deprecated_remove_at %}
{{ sub | terminal_deprecation(width=terminal_width) }}
{%- endif %}
{%- for group in sub.arg_groups %}
{%- for arg in group.items %}
{%- if sub.flattened_next_line_help %}
  {{ arg.usage | trim }}
{%- if arg.row %}
{{ arg.row }}
{%- endif %}
{%- elif arg.help_rendered %}
  {{ arg.usage | ljust(width=arg.usage_col_width) }}  {{ arg.help_rendered }}
{%- elif arg.row %}
  {{ arg.usage | trim }}
{{ arg.row }}
{%- else %}
  {{ arg.usage | trim }}
{%- endif %}
{%- if arg.admonitions %}
{%- for admonition in arg.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.choices %}
{{ arg.choices.choices | terminal_annotation(label="[possible values: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.env %}
{{ arg.choices.env | terminal_annotation(label="[choices env: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_possible_values and arg.choices and arg.choices.run %}
{{ arg.choices.run | terminal_annotation(label="[possible values: output of `", suffix="`]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_env and arg.env %}
{{ arg.env | terminal_annotation(label="[env: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not arg.hide_env %}{% for env in arg.env_fallback %}
{{ env | terminal_annotation(label="[env fallback: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endfor %}{% for env in arg.deprecated_env %}
{{ env | terminal_annotation(label="[deprecated env: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endfor %}{%- endif %}
{%- if not arg.hide_default_value and arg.default %}
{{ arg.default | terminal_annotation(label="(default: ", suffix=")", indent="    ", width=terminal_width) }}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- for group in sub.flag_groups %}
{%- for flag in group.items %}
{%- if sub.flattened_next_line_help %}
  {{ flag.display_usage }}
{%- if flag.row %}
{{ flag.row }}
{%- endif %}
{%- elif flag.help_rendered %}
  {{ flag.display_usage | ljust(width=flag.usage_col_width) }}  {{ flag.help_rendered }}
{%- elif flag.row %}
  {{ flag.display_usage }}
{{ flag.row }}
{%- else %}
  {{ flag.display_usage }}
{%- endif %}
{%- if flag.admonitions %}
{%- for admonition in flag.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if flag.arg and flag.arg.admonitions %}
{%- for admonition in flag.arg.admonitions %}
    {% if admonition.kind == "warning" %}{{ admonition.text | terminal_label(label="Warning", width=terminal_width, indent=4) | indent(width=4) }}{% else %}{{ admonition.text | terminal_label(label="Note", width=terminal_width, indent=4) | indent(width=4) }}{% endif %}
{%- endfor %}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.choices %}
{{ flag.arg.choices.choices | terminal_annotation(label="[possible values: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.env %}
{{ flag.arg.choices.env | terminal_annotation(label="[choices env: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_possible_values and flag.arg.choices and flag.arg.choices.run %}
{{ flag.arg.choices.run | terminal_annotation(label="[possible values: output of `", suffix="`]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_env and flag.env %}
{{ flag.env | terminal_annotation(label="[env: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if not flag.hide_env %}{% for env in flag.env_fallback %}
{{ env | terminal_annotation(label="[env fallback: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endfor %}{% for env in flag.deprecated_env %}
{{ env | terminal_annotation(label="[deprecated env: ", suffix="]", indent="    ", width=terminal_width) }}
{%- endfor %}{%- endif %}
{%- if not flag.hide_default_value and flag.default %}
{{ flag.default | terminal_annotation(label="(default: ", suffix=")", indent="    ", width=terminal_width) }}
{%- endif %}
{%- if flag.deprecated or flag.deprecated_warn_at or flag.deprecated_remove_at %}
{{ flag | terminal_deprecation(indent="    ", width=terminal_width) }}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endfor %}
{%- endif %}{{ mark_after_help }}

{%- if cmd.examples %}

Examples:
{%- for example in cmd.examples %}
{%- if not loop.first %}
{% endif %}
{%- if example.header %}
  {{ example.header }}:
{%- endif %}
{%- if example.help %}
    {{ example.help }}
{%- endif %}
    $ {{ example.code | indent_continuation(indent=4) }}
{%- endfor %}
{%- elif root and spec.examples %}

Examples:
{%- for example in spec.examples %}
{%- if not loop.first %}
{% endif %}
{%- if example.header %}
  {{ example.header }}:
{%- endif %}
{%- if example.help %}
    {{ example.help }}
{%- endif %}
    $ {{ example.code | indent_continuation(indent=4) }}
{%- endfor %}
{%- endif %}

{%- if cmd.after_help_long %}

{{ cmd.after_help_long | terminal_wrap(width=terminal_width) }}
{%- elif cmd.after_help %}

{{ cmd.after_help | terminal_wrap(width=terminal_width) }}
{%- elif root and spec.after_help_long %}

{{ spec.after_help_long | terminal_wrap(width=terminal_width) }}
{%- elif root and spec.after_help %}

{{ spec.after_help | terminal_wrap(width=terminal_width) }}
{%- endif %}

{%- if root and (spec.author or spec.license) %}
{% if spec.author %}
Author: {{ spec.author }}
{%- endif %}
{%- if spec.license %}
License: {{ spec.license }}
{%- endif %}
{%- endif -%}