bashly 1.4.0.rc2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77fc095074710d1003657f7ee7360e06e6864c9142d283d8bab88a9776fc737f
4
- data.tar.gz: fae57e0c6bdf23a09d83bb280a4161b2e4b0de0e46518a44a1c36f902f9993cb
3
+ metadata.gz: eca947512ada2ac873e3b6d399d75b441c97eb1ac4c56f5e1e8c1017fc9389ac
4
+ data.tar.gz: f340d79b2f493871f3601c3be689eaf846a4f865eabb34cb3beeaab529ddf2eb
5
5
  SHA512:
6
- metadata.gz: a23dd4c92491a97aef54990418b930ae38ce826ede3bf1352c18f99ac8c53d5391e613eef113f5996c2757a60d5c9ebf96fe7e277e69a6a07456d02df35c2b28
7
- data.tar.gz: 369a787f5851da5ac1b07afe6f7ddb985ebd64fc3ffe08aa5379376b3f8ddbc53e313dc31ba832096361a15ebf5aa973d6fd4dabfe64d7f8c6249799a9a7e1f9
6
+ metadata.gz: 1fba0f5a53ebd3f4a209a1a4a12b7e132d20b06aba4d9dac4afa199b240f0099e39be1905a4d5db95d37255cebdf62d4c7058131b3b2ee1c2ba54a09d4054de5
7
+ data.tar.gz: 688fb3b6a40e18a2d63a1bde4ddbeaa999d13c8f8b1b5487af3cfe4a1487d0fc0154422869138beed62b04cc1bc321902046ec1f805aa2226f3085b5d619e20d
@@ -4,121 +4,136 @@
4
4
  # completely (https://github.com/bashly-framework/completely)
5
5
  # Modifying it manually is not recommended
6
6
 
7
- _bashly_completions_route_flag_expects_value() {
7
+ _bashly_completions_node_flag_state() {
8
8
  case "$1:$2" in
9
- 4:--env|4:-e) return 0 ;;
10
- 4:--wrap|4:-r) return 0 ;;
11
- 5:--source|5:-s) return 0 ;;
12
- 8:--show|8:-s) return 0 ;;
9
+ 0:--help|0:-h) return 0 ;;
10
+ 0:--version|0:-v) return 0 ;;
11
+ 1:--help|1:-h) return 0 ;;
12
+ 1:--minimal|1:-m) return 0 ;;
13
+ 2:--help|2:-h) return 0 ;;
14
+ 3:--help|3:-h) return 0 ;;
15
+ 3:--verbose|3:-v) return 0 ;;
16
+ 4:--env|4:-e) return 2 ;;
17
+ 4:--wrap|4:-r) return 2 ;;
18
+ 4:--help|4:-h) return 0 ;;
19
+ 4:--force|4:-f) return 0 ;;
20
+ 4:--quiet|4:-q) return 0 ;;
21
+ 4:--upgrade|4:-u) return 0 ;;
22
+ 4:--watch|4:-w) return 0 ;;
23
+ 5:--source|5:-s) return 2 ;;
24
+ 5:--help|5:-h) return 0 ;;
25
+ 5:--force|5:-f) return 0 ;;
26
+ 5:--list|5:-l) return 0 ;;
27
+ 6:--help|6:-h) return 0 ;;
28
+ 6:--index|6:-i) return 0 ;;
29
+ 7:--help|7:-h) return 0 ;;
30
+ 7:--install|7:-i) return 0 ;;
31
+ 7:--uninstall|7:-u) return 0 ;;
32
+ 8:--show|8:-s) return 2 ;;
33
+ 8:--help|8:-h) return 0 ;;
34
+ 8:--watch|8:-w) return 0 ;;
35
+ 8:--list|8:-l) return 0 ;;
36
+ 8:--about|8:-a) return 0 ;;
37
+ 9:--help|9:-h) return 0 ;;
13
38
  esac
14
39
 
15
40
  return 1
16
41
  }
17
42
 
18
- _bashly_completions_resolve_route() {
19
- route_id=
20
- route_word_count=-1
21
- route_has_positionals=0
22
- positional_index=0
23
- if (( ${#non_options[@]} >= 0 )) &&
24
- (( 0 > route_word_count ))
25
- then
26
- route_id=0
27
- route_word_count=0
28
- route_has_positionals=0
29
- positional_index=$((${#non_options[@]} - 0))
30
- fi
31
-
32
- if (( ${#non_options[@]} >= 1 )) &&
33
- (( 1 > route_word_count )) &&
34
- [[ "${non_options[0]}" == "init" || "${non_options[0]}" == "i" ]]
35
- then
36
- route_id=1
37
- route_word_count=1
38
- route_has_positionals=0
39
- positional_index=$((${#non_options[@]} - 1))
40
- fi
41
-
42
- if (( ${#non_options[@]} >= 1 )) &&
43
- (( 1 > route_word_count )) &&
44
- [[ "${non_options[0]}" == "preview" || "${non_options[0]}" == "p" ]]
45
- then
46
- route_id=2
47
- route_word_count=1
48
- route_has_positionals=0
49
- positional_index=$((${#non_options[@]} - 1))
50
- fi
51
-
52
- if (( ${#non_options[@]} >= 1 )) &&
53
- (( 1 > route_word_count )) &&
54
- [[ "${non_options[0]}" == "validate" || "${non_options[0]}" == "v" ]]
55
- then
56
- route_id=3
57
- route_word_count=1
58
- route_has_positionals=0
59
- positional_index=$((${#non_options[@]} - 1))
60
- fi
61
-
62
- if (( ${#non_options[@]} >= 1 )) &&
63
- (( 1 > route_word_count )) &&
64
- [[ "${non_options[0]}" == "generate" || "${non_options[0]}" == "build" || "${non_options[0]}" == "g" ]]
65
- then
66
- route_id=4
67
- route_word_count=1
68
- route_has_positionals=0
69
- positional_index=$((${#non_options[@]} - 1))
70
- fi
71
-
72
- if (( ${#non_options[@]} >= 1 )) &&
73
- (( 1 > route_word_count )) &&
74
- [[ "${non_options[0]}" == "add" || "${non_options[0]}" == "a" ]]
75
- then
76
- route_id=5
77
- route_word_count=1
78
- route_has_positionals=1
79
- positional_index=$((${#non_options[@]} - 1))
80
- fi
81
-
82
- if (( ${#non_options[@]} >= 1 )) &&
83
- (( 1 > route_word_count )) &&
84
- [[ "${non_options[0]}" == "doc" ]]
85
- then
86
- route_id=6
87
- route_word_count=1
88
- route_has_positionals=1
89
- positional_index=$((${#non_options[@]} - 1))
90
- fi
43
+ _bashly_completions_option_seen() {
44
+ local completed_option option_name
45
+ for completed_option in "${completed_options[@]}"; do
46
+ for option_name in "$@"; do
47
+ [[ "$completed_option" == "$option_name" ]] && return 0
48
+ done
49
+ done
91
50
 
92
- if (( ${#non_options[@]} >= 1 )) &&
93
- (( 1 > route_word_count )) &&
94
- [[ "${non_options[0]}" == "completions" || "${non_options[0]}" == "c" ]]
95
- then
96
- route_id=7
97
- route_word_count=1
98
- route_has_positionals=0
99
- positional_index=$((${#non_options[@]} - 1))
100
- fi
51
+ return 1
52
+ }
101
53
 
102
- if (( ${#non_options[@]} >= 1 )) &&
103
- (( 1 > route_word_count )) &&
104
- [[ "${non_options[0]}" == "render" ]]
105
- then
106
- route_id=8
107
- route_word_count=1
108
- route_has_positionals=1
109
- positional_index=$((${#non_options[@]} - 1))
110
- fi
54
+ _bashly_completions_resolve_node() {
55
+ node_id=0
56
+ node_word_count=0
57
+ positional_index=0
111
58
 
112
- if (( ${#non_options[@]} >= 1 )) &&
113
- (( 1 > route_word_count )) &&
114
- [[ "${non_options[0]}" == "shell" || "${non_options[0]}" == "s" ]]
115
- then
116
- route_id=9
117
- route_word_count=1
118
- route_has_positionals=0
119
- positional_index=$((${#non_options[@]} - 1))
120
- fi
59
+ local word
60
+ for word in "${non_options[@]}"; do
61
+ case "$node_id:$word" in
62
+ 0:init)
63
+ node_id=1
64
+ node_word_count=1
65
+ ;;
66
+ 0:i)
67
+ node_id=1
68
+ node_word_count=1
69
+ ;;
70
+ 0:preview)
71
+ node_id=2
72
+ node_word_count=1
73
+ ;;
74
+ 0:p)
75
+ node_id=2
76
+ node_word_count=1
77
+ ;;
78
+ 0:validate)
79
+ node_id=3
80
+ node_word_count=1
81
+ ;;
82
+ 0:v)
83
+ node_id=3
84
+ node_word_count=1
85
+ ;;
86
+ 0:generate)
87
+ node_id=4
88
+ node_word_count=1
89
+ ;;
90
+ 0:build)
91
+ node_id=4
92
+ node_word_count=1
93
+ ;;
94
+ 0:g)
95
+ node_id=4
96
+ node_word_count=1
97
+ ;;
98
+ 0:add)
99
+ node_id=5
100
+ node_word_count=1
101
+ ;;
102
+ 0:a)
103
+ node_id=5
104
+ node_word_count=1
105
+ ;;
106
+ 0:doc)
107
+ node_id=6
108
+ node_word_count=1
109
+ ;;
110
+ 0:completions)
111
+ node_id=7
112
+ node_word_count=1
113
+ ;;
114
+ 0:c)
115
+ node_id=7
116
+ node_word_count=1
117
+ ;;
118
+ 0:render)
119
+ node_id=8
120
+ node_word_count=1
121
+ ;;
122
+ 0:shell)
123
+ node_id=9
124
+ node_word_count=1
125
+ ;;
126
+ 0:s)
127
+ node_id=9
128
+ node_word_count=1
129
+ ;;
130
+ *)
131
+ break
132
+ ;;
133
+ esac
134
+ done
121
135
 
136
+ positional_index=$((${#non_options[@]} - node_word_count))
122
137
  }
123
138
 
124
139
  _bashly_completions() {
@@ -135,11 +150,12 @@ _bashly_completions() {
135
150
 
136
151
  local non_options=()
137
152
  local completed_options=()
138
- local route_id=
139
- local route_word_count=-1
140
- local route_has_positionals=0
153
+ local node_id=
154
+ local node_word_count=-1
141
155
  local positional_index=0
142
- _bashly_completions_resolve_route
156
+ local invalid_completion=0
157
+ local flag_state=0
158
+ _bashly_completions_resolve_node
143
159
 
144
160
  local skip_next=0
145
161
  for word in "${completed[@]}"; do
@@ -149,25 +165,28 @@ _bashly_completions() {
149
165
  fi
150
166
 
151
167
  if [[ "${word:0:1}" == "-" ]]; then
168
+ _bashly_completions_node_flag_state "$node_id" "$word"
169
+ flag_state=$?
170
+ if (( flag_state == 1 )); then
171
+ invalid_completion=1
172
+ break
173
+ fi
174
+
152
175
  completed_options+=("$word")
153
- if _bashly_completions_route_flag_expects_value "$route_id" "$word"; then
176
+ if (( flag_state == 2 )); then
154
177
  skip_next=1
155
178
  fi
156
179
  continue
157
180
  fi
158
181
 
159
182
  non_options+=("$word")
160
- _bashly_completions_resolve_route
183
+ _bashly_completions_resolve_node
161
184
  done
162
185
 
163
186
  COMPREPLY=()
187
+ (( invalid_completion )) && return
164
188
 
165
- if [[ -z "$route_id" ]] || { (( route_word_count == 0 )) && (( !route_has_positionals )) && [[ "${cur:0:1}" != "-" ]]; }; then
166
- while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "init i preview p validate v generate build g add a doc completions c render shell s" -- "$cur")
167
- return
168
- fi
169
-
170
- case "$route_id:$prev" in
189
+ case "$node_id:$prev" in
171
190
  4:--env|4:-e)
172
191
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "development production" -- "$cur")
173
192
  return
@@ -183,329 +202,106 @@ _bashly_completions() {
183
202
  ;;
184
203
  esac
185
204
 
205
+ if [[ "${cur:0:1}" != "-" ]] && (( positional_index == 0 )); then
206
+ case "$node_id" in
207
+ 0)
208
+ while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "init i preview p validate v generate build g add a doc completions c render shell s" -- "$cur")
209
+ return
210
+ ;;
211
+ esac
212
+ fi
213
+
186
214
  if [[ "${cur:0:1}" == "-" ]]; then
187
- case "$route_id" in
215
+ case "$node_id" in
188
216
  0)
189
217
  local words=()
190
- local option_seen=0
191
- for completed_option in "${completed_options[@]}"; do
192
- case "$completed_option" in
193
- --help|-h) option_seen=1 ;;
194
- esac
195
- done
196
- if ((!option_seen)); then
197
- words+=("--help" "-h")
198
- fi
199
- local option_seen=0
200
- for completed_option in "${completed_options[@]}"; do
201
- case "$completed_option" in
202
- --version|-v) option_seen=1 ;;
203
- esac
204
- done
205
- if ((!option_seen)); then
206
- words+=("--version" "-v")
207
- fi
218
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
219
+ _bashly_completions_option_seen "--version" "-v" || words+=("--version" "-v")
208
220
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
209
221
  return
210
222
  ;;
211
223
  1)
212
224
  local words=()
213
- local option_seen=0
214
- for completed_option in "${completed_options[@]}"; do
215
- case "$completed_option" in
216
- --help|-h) option_seen=1 ;;
217
- esac
218
- done
219
- if ((!option_seen)); then
220
- words+=("--help" "-h")
221
- fi
222
- local option_seen=0
223
- for completed_option in "${completed_options[@]}"; do
224
- case "$completed_option" in
225
- --minimal|-m) option_seen=1 ;;
226
- esac
227
- done
228
- if ((!option_seen)); then
229
- words+=("--minimal" "-m")
230
- fi
225
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
226
+ _bashly_completions_option_seen "--minimal" "-m" || words+=("--minimal" "-m")
231
227
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
232
228
  return
233
229
  ;;
234
230
  2)
235
231
  local words=()
236
- local option_seen=0
237
- for completed_option in "${completed_options[@]}"; do
238
- case "$completed_option" in
239
- --help|-h) option_seen=1 ;;
240
- esac
241
- done
242
- if ((!option_seen)); then
243
- words+=("--help" "-h")
244
- fi
232
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
245
233
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
246
234
  return
247
235
  ;;
248
236
  3)
249
237
  local words=()
250
- local option_seen=0
251
- for completed_option in "${completed_options[@]}"; do
252
- case "$completed_option" in
253
- --help|-h) option_seen=1 ;;
254
- esac
255
- done
256
- if ((!option_seen)); then
257
- words+=("--help" "-h")
258
- fi
259
- local option_seen=0
260
- for completed_option in "${completed_options[@]}"; do
261
- case "$completed_option" in
262
- --verbose|-v) option_seen=1 ;;
263
- esac
264
- done
265
- if ((!option_seen)); then
266
- words+=("--verbose" "-v")
267
- fi
238
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
239
+ _bashly_completions_option_seen "--verbose" "-v" || words+=("--verbose" "-v")
268
240
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
269
241
  return
270
242
  ;;
271
243
  4)
272
244
  local words=()
273
- local option_seen=0
274
- for completed_option in "${completed_options[@]}"; do
275
- case "$completed_option" in
276
- --help|-h) option_seen=1 ;;
277
- esac
278
- done
279
- if ((!option_seen)); then
280
- words+=("--help" "-h")
281
- fi
282
- local option_seen=0
283
- for completed_option in "${completed_options[@]}"; do
284
- case "$completed_option" in
285
- --env|-e) option_seen=1 ;;
286
- esac
287
- done
288
- if ((!option_seen)); then
289
- words+=("--env" "-e")
290
- fi
291
- local option_seen=0
292
- for completed_option in "${completed_options[@]}"; do
293
- case "$completed_option" in
294
- --force|-f) option_seen=1 ;;
295
- esac
296
- done
297
- if ((!option_seen)); then
298
- words+=("--force" "-f")
299
- fi
300
- local option_seen=0
301
- for completed_option in "${completed_options[@]}"; do
302
- case "$completed_option" in
303
- --quiet|-q) option_seen=1 ;;
304
- esac
305
- done
306
- if ((!option_seen)); then
307
- words+=("--quiet" "-q")
308
- fi
309
- local option_seen=0
310
- for completed_option in "${completed_options[@]}"; do
311
- case "$completed_option" in
312
- --upgrade|-u) option_seen=1 ;;
313
- esac
314
- done
315
- if ((!option_seen)); then
316
- words+=("--upgrade" "-u")
317
- fi
318
- local option_seen=0
319
- for completed_option in "${completed_options[@]}"; do
320
- case "$completed_option" in
321
- --watch|-w) option_seen=1 ;;
322
- esac
323
- done
324
- if ((!option_seen)); then
325
- words+=("--watch" "-w")
326
- fi
327
- local option_seen=0
328
- for completed_option in "${completed_options[@]}"; do
329
- case "$completed_option" in
330
- --wrap|-r) option_seen=1 ;;
331
- esac
332
- done
333
- if ((!option_seen)); then
334
- words+=("--wrap" "-r")
335
- fi
245
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
246
+ _bashly_completions_option_seen "--env" "-e" || words+=("--env" "-e")
247
+ _bashly_completions_option_seen "--force" "-f" || words+=("--force" "-f")
248
+ _bashly_completions_option_seen "--quiet" "-q" || words+=("--quiet" "-q")
249
+ _bashly_completions_option_seen "--upgrade" "-u" || words+=("--upgrade" "-u")
250
+ _bashly_completions_option_seen "--watch" "-w" || words+=("--watch" "-w")
251
+ _bashly_completions_option_seen "--wrap" "-r" || words+=("--wrap" "-r")
336
252
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
337
253
  return
338
254
  ;;
339
255
  5)
340
256
  local words=()
341
- local option_seen=0
342
- for completed_option in "${completed_options[@]}"; do
343
- case "$completed_option" in
344
- --help|-h) option_seen=1 ;;
345
- esac
346
- done
347
- if ((!option_seen)); then
348
- words+=("--help" "-h")
349
- fi
350
- local option_seen=0
351
- for completed_option in "${completed_options[@]}"; do
352
- case "$completed_option" in
353
- --force|-f) option_seen=1 ;;
354
- esac
355
- done
356
- if ((!option_seen)); then
357
- words+=("--force" "-f")
358
- fi
359
- local option_seen=0
360
- for completed_option in "${completed_options[@]}"; do
361
- case "$completed_option" in
362
- --list|-l) option_seen=1 ;;
363
- esac
364
- done
365
- if ((!option_seen)); then
366
- words+=("--list" "-l")
367
- fi
368
- local option_seen=0
369
- for completed_option in "${completed_options[@]}"; do
370
- case "$completed_option" in
371
- --source|-s) option_seen=1 ;;
372
- esac
373
- done
374
- if ((!option_seen)); then
375
- words+=("--source" "-s")
376
- fi
257
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
258
+ _bashly_completions_option_seen "--force" "-f" || words+=("--force" "-f")
259
+ _bashly_completions_option_seen "--list" "-l" || words+=("--list" "-l")
260
+ _bashly_completions_option_seen "--source" "-s" || words+=("--source" "-s")
377
261
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
378
262
  return
379
263
  ;;
380
264
  6)
381
265
  local words=()
382
- local option_seen=0
383
- for completed_option in "${completed_options[@]}"; do
384
- case "$completed_option" in
385
- --help|-h) option_seen=1 ;;
386
- esac
387
- done
388
- if ((!option_seen)); then
389
- words+=("--help" "-h")
390
- fi
391
- local option_seen=0
392
- for completed_option in "${completed_options[@]}"; do
393
- case "$completed_option" in
394
- --index|-i) option_seen=1 ;;
395
- esac
396
- done
397
- if ((!option_seen)); then
398
- words+=("--index" "-i")
399
- fi
266
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
267
+ _bashly_completions_option_seen "--index" "-i" || words+=("--index" "-i")
400
268
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
401
269
  return
402
270
  ;;
403
271
  7)
404
272
  local words=()
405
- local option_seen=0
406
- for completed_option in "${completed_options[@]}"; do
407
- case "$completed_option" in
408
- --help|-h) option_seen=1 ;;
409
- esac
410
- done
411
- if ((!option_seen)); then
412
- words+=("--help" "-h")
413
- fi
414
- local option_seen=0
415
- for completed_option in "${completed_options[@]}"; do
416
- case "$completed_option" in
417
- --install|-i) option_seen=1 ;;
418
- esac
419
- done
420
- if ((!option_seen)); then
421
- words+=("--install" "-i")
422
- fi
423
- local option_seen=0
424
- for completed_option in "${completed_options[@]}"; do
425
- case "$completed_option" in
426
- --uninstall|-u) option_seen=1 ;;
427
- esac
428
- done
429
- if ((!option_seen)); then
430
- words+=("--uninstall" "-u")
431
- fi
273
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
274
+ _bashly_completions_option_seen "--install" "-i" || words+=("--install" "-i")
275
+ _bashly_completions_option_seen "--uninstall" "-u" || words+=("--uninstall" "-u")
432
276
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
433
277
  return
434
278
  ;;
435
279
  8)
436
280
  local words=()
437
- local option_seen=0
438
- for completed_option in "${completed_options[@]}"; do
439
- case "$completed_option" in
440
- --help|-h) option_seen=1 ;;
441
- esac
442
- done
443
- if ((!option_seen)); then
444
- words+=("--help" "-h")
445
- fi
446
- local option_seen=0
447
- for completed_option in "${completed_options[@]}"; do
448
- case "$completed_option" in
449
- --watch|-w) option_seen=1 ;;
450
- esac
451
- done
452
- if ((!option_seen)); then
453
- words+=("--watch" "-w")
454
- fi
455
- local option_seen=0
456
- for completed_option in "${completed_options[@]}"; do
457
- case "$completed_option" in
458
- --show|-s) option_seen=1 ;;
459
- esac
460
- done
461
- if ((!option_seen)); then
462
- words+=("--show" "-s")
463
- fi
464
- local option_seen=0
465
- for completed_option in "${completed_options[@]}"; do
466
- case "$completed_option" in
467
- --list|-l) option_seen=1 ;;
468
- esac
469
- done
470
- if ((!option_seen)); then
471
- words+=("--list" "-l")
472
- fi
473
- local option_seen=0
474
- for completed_option in "${completed_options[@]}"; do
475
- case "$completed_option" in
476
- --about|-a) option_seen=1 ;;
477
- esac
478
- done
479
- if ((!option_seen)); then
480
- words+=("--about" "-a")
481
- fi
281
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
282
+ _bashly_completions_option_seen "--watch" "-w" || words+=("--watch" "-w")
283
+ _bashly_completions_option_seen "--show" "-s" || words+=("--show" "-s")
284
+ _bashly_completions_option_seen "--list" "-l" || words+=("--list" "-l")
285
+ _bashly_completions_option_seen "--about" "-a" || words+=("--about" "-a")
482
286
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
483
287
  return
484
288
  ;;
485
289
  9)
486
290
  local words=()
487
- local option_seen=0
488
- for completed_option in "${completed_options[@]}"; do
489
- case "$completed_option" in
490
- --help|-h) option_seen=1 ;;
491
- esac
492
- done
493
- if ((!option_seen)); then
494
- words+=("--help" "-h")
495
- fi
291
+ _bashly_completions_option_seen "--help" "-h" || words+=("--help" "-h")
496
292
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "${words[*]}" -- "$cur")
497
293
  return
498
294
  ;;
499
295
  esac
500
296
  fi
501
297
 
502
- case "$route_id:$positional_index" in
298
+ case "$node_id:$positional_index" in
503
299
  5:0)
504
300
  while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "colors completions completions_script completions_yaml config help hooks ini lib render_markdown render_markdown_github render_mandoc settings stacktrace strings validations yaml" -- "$cur")
505
301
  return
506
302
  ;;
507
303
  6:0)
508
- while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "arg arg.allowed arg.completions arg.default arg.help arg.name arg.repeatable arg.required arg.validate command command.alias command.args command.catch_all command.commands command.completions command.default command.dependencies command.environment_variables command.examples command.expose command.extensible command.filename command.filters command.flags command.footer command.function command.group command.help command.help_header_override command.name command.private command.variables command.version environment_variable environment_variable.default environment_variable.help environment_variable.name environment_variable.private environment_variable.required environment_variable.validate flag flag.allowed flag.arg flag.completions flag.conflicts flag.default flag.help flag.long flag.needs flag.private flag.repeatable flag.required flag.short flag.unique flag.validate variable variable.name variable.value" -- "$cur")
304
+ while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "arg arg.allowed arg.completions arg.default arg.help arg.name arg.repeatable arg.required arg.validate command command.alias command.args command.catch_all command.commands command.completions command.default command.dependencies command.environment_variables command.examples command.expose command.extensible command.filename command.filters command.flags command.footer command.function command.group command.help command.help_header_override command.name command.private command.variables command.version environment_variable environment_variable.default environment_variable.help environment_variable.name environment_variable.private environment_variable.required environment_variable.validate flag flag.alias flag.allowed flag.arg flag.completions flag.conflicts flag.default flag.help flag.long flag.needs flag.negatable flag.private flag.repeatable flag.required flag.short flag.unique flag.validate variable variable.name variable.value" -- "$cur")
509
305
  return
510
306
  ;;
511
307
  8:0)
@@ -118,6 +118,7 @@ tokens:
118
118
  - environment_variable.required
119
119
  - environment_variable.validate
120
120
  - flag
121
+ - flag.alias
121
122
  - flag.allowed
122
123
  - flag.arg
123
124
  - flag.completions
@@ -126,6 +127,7 @@ tokens:
126
127
  - flag.help
127
128
  - flag.long
128
129
  - flag.needs
130
+ - flag.negatable
129
131
  - flag.private
130
132
  - flag.repeatable
131
133
  - flag.required
@@ -126,9 +126,11 @@ module Bashly
126
126
  assert_optional_string "#{key}.short", value['short']
127
127
  assert_optional_string "#{key}.help", value['help']
128
128
  assert_optional_string "#{key}.arg", value['arg']
129
+ assert_string_or_array "#{key}.alias", value['alias']
129
130
  assert_string_or_array "#{key}.default", value['default']
130
131
  assert_string_or_array "#{key}.validate", value['validate']
131
132
 
133
+ assert_boolean "#{key}.negatable", value['negatable']
132
134
  assert_boolean "#{key}.private", value['private']
133
135
  assert_boolean "#{key}.repeatable", value['repeatable']
134
136
  assert_boolean "#{key}.unique", value['unique']
@@ -139,10 +141,21 @@ module Bashly
139
141
 
140
142
  assert value['long'].match(/^--[a-zA-Z0-9_-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
141
143
  assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
144
+ Array(value['alias']).each_with_index do |flag_alias, index|
145
+ alias_key = value['alias'].is_a?(Array) ? "#{key}.alias[#{index}]" : "#{key}.alias"
146
+ assert_flag_alias alias_key, flag_alias
147
+ end
142
148
  refute value['arg'].match(/^-/), "#{key}.arg must not start with '-'" if value['arg']
143
149
 
144
150
  refute value['required'] && value['default'], "#{key} cannot have both nub`required` and nub`default`"
145
151
 
152
+ if value['negatable']
153
+ assert value['long'], "#{key}.negatable requires nub`long`"
154
+ refute value['arg'], "#{key}.negatable does not make sense with nub`arg`"
155
+ refute value['repeatable'], "#{key}.negatable does not make sense with nub`repeatable`"
156
+ refute value['required'], "#{key}.negatable does not make sense with nub`required`"
157
+ end
158
+
146
159
  if value['default']
147
160
  assert value['arg'], "#{key}.default does not make sense without nub`arg`"
148
161
  end
@@ -165,6 +178,13 @@ module Bashly
165
178
  end
166
179
  end
167
180
 
181
+ def assert_flag_alias(key, value)
182
+ assert(
183
+ value.match(/^--[a-zA-Z0-9_-]+$/) || value.match(/^-[a-zA-Z0-9]$/),
184
+ "#{key} must be in the form of '--name' or '-n'"
185
+ )
186
+ end
187
+
168
188
  def assert_env_var(key, value)
169
189
  assert_hash key, value, keys: Script::EnvironmentVariable.option_keys
170
190
  assert_string "#{key}.name", value['name']
@@ -222,8 +242,7 @@ module Bashly
222
242
  assert_array "#{key}.variables", value['variables'], of: :var
223
243
 
224
244
  assert_uniq "#{key}.commands", value['commands'], %w[name alias]
225
- assert_uniq "#{key}.flags", value['flags'], 'long'
226
- assert_uniq "#{key}.flags", value['flags'], 'short'
245
+ assert_uniq_flags key, value['flags']
227
246
  assert_uniq "#{key}.args", value['args'], 'name'
228
247
 
229
248
  if value['function']
@@ -265,5 +284,23 @@ module Bashly
265
284
  refute value['extensible'], "#{key}.extensible makes no sense"
266
285
  end
267
286
  end
287
+
288
+ def assert_uniq_flags(key, flags)
289
+ return unless flags
290
+
291
+ list = flags.flat_map do |flag|
292
+ [flag['long'], flag['short'], *Array(flag['alias']), negated_flag_name(flag)].compact
293
+ end
294
+
295
+ nonuniqs = list.nonuniq
296
+ assert nonuniqs.empty?,
297
+ "#{key}.flags contains non-unique elements (#{nonuniqs.join ', '}) in long or short or alias"
298
+ end
299
+
300
+ def negated_flag_name(flag)
301
+ return unless flag['negatable'] == true && flag['long']
302
+
303
+ "--no-#{flag['long'].delete_prefix '--'}"
304
+ end
268
305
  end
269
306
  end
@@ -13,6 +13,17 @@ flag:
13
13
  help: Repository user name
14
14
  required: true
15
15
 
16
+ flag.alias:
17
+ help: Specify one or more aliases for this flag. Each alias must include the `--` or `-` prefix.
18
+ url: https://bashly.dev/configuration/flag/#alias
19
+ example: |-
20
+ flags:
21
+ - long: --container
22
+ short: -c
23
+ alias: [--pod, -p]
24
+ arg: name
25
+ help: Container name
26
+
16
27
  flag.allowed:
17
28
  help: Specify a list of allowed values. Can be used in conjunction with `default` and `required`, and must be accompanied by `arg`.
18
29
  url: https://bashly.dev/configuration/flag/#allowed
@@ -136,6 +147,15 @@ flag.needs:
136
147
  help: Where to add the alias
137
148
  needs: [--add]
138
149
 
150
+ flag.negatable:
151
+ help: Allow a boolean long flag to also be disabled with its `--no-` form.
152
+ url: https://bashly.dev/configuration/flag/#negatable
153
+ example: |-
154
+ flags:
155
+ - long: --color
156
+ help: Enable color output
157
+ negatable: true
158
+
139
159
  flag.private:
140
160
  help: Specify that this flag should not be displayed in the help text.
141
161
  url: https://bashly.dev/configuration/flag/#private
@@ -205,4 +225,4 @@ flag.validate:
205
225
  - long: --config
206
226
  arg: path
207
227
  help: Load configuration from a file
208
- validate: file_exists
228
+ validate: file_exists
@@ -10,20 +10,28 @@ module Bashly
10
10
  class << self
11
11
  def option_keys
12
12
  @option_keys ||= %i[
13
- allowed arg completions conflicts default help long needs
14
- private repeatable required short unique validate
13
+ alias allowed arg completions conflicts default help long needs
14
+ negatable private repeatable required short unique validate
15
15
  ]
16
16
  end
17
17
  end
18
18
 
19
+ def alt
20
+ return [] unless options['alias']
21
+
22
+ options['alias'].is_a?(String) ? [options['alias']] : options['alias']
23
+ end
24
+
19
25
  def aliases
20
- if long && short
21
- [long, short]
22
- elsif long
23
- [long]
24
- else
25
- [short]
26
- end
26
+ [long, negated_long, short].compact + alt
27
+ end
28
+
29
+ def positive_aliases
30
+ primary_aliases + alt
31
+ end
32
+
33
+ def negated_long
34
+ "--no-#{long_without_prefix}" if negatable && long
27
35
  end
28
36
 
29
37
  def default_string
@@ -41,12 +49,30 @@ module Bashly
41
49
  end
42
50
 
43
51
  def usage_string(extended: false)
44
- result = [aliases.join(', ')]
52
+ result = [usage_aliases.join(', ')]
45
53
  result << arg.upcase if arg
46
54
  result << strings[:required] if required && extended
47
55
  result << strings[:repeatable] if repeatable && extended
48
56
  result.join ' '
49
57
  end
58
+
59
+ private
60
+
61
+ def primary_aliases
62
+ [long, short].compact
63
+ end
64
+
65
+ def usage_aliases
66
+ [usage_long, short].compact + alt
67
+ end
68
+
69
+ def usage_long
70
+ negatable && long ? "--[no-]#{long_without_prefix}" : long
71
+ end
72
+
73
+ def long_without_prefix
74
+ long.delete_prefix '--'
75
+ end
50
76
  end
51
77
  end
52
78
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.4.0.rc2'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -1,6 +1,13 @@
1
1
  = view_marker
2
2
 
3
- > {{ aliases.join " | " }})
3
+ > {{ positive_aliases.join " | " }})
4
4
  = render(arg ? :argfile_case_arg : :argfile_case_no_arg).indent 2
5
5
  > ;;
6
6
  >
7
+
8
+ if negatable
9
+ > {{ negated_long }})
10
+ > unset "args[{{ name }}]"
11
+ > ;;
12
+ >
13
+ end
@@ -1,6 +1,14 @@
1
1
  = view_marker
2
2
 
3
- > {{ aliases.join " | " }})
3
+ > {{ positive_aliases.join " | " }})
4
4
  = render(:conflicts).indent 2
5
5
  = render(arg ? :case_arg : :case_no_arg).indent 2
6
6
  >
7
+
8
+ if negatable
9
+ > {{ negated_long }})
10
+ > unset "args[{{ name }}]"
11
+ > shift
12
+ > ;;
13
+ >
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.rc2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.8.0.rc4
32
+ version: 0.8.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.8.0.rc4
39
+ version: 0.8.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: gtx
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -121,20 +121,6 @@ dependencies:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
123
  version: 0.7.2
124
- - !ruby/object:Gem::Dependency
125
- name: logger
126
- requirement: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - "~>"
129
- - !ruby/object:Gem::Version
130
- version: '1.7'
131
- type: :runtime
132
- prerelease: false
133
- version_requirements: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '1.7'
138
124
  description: Generate bash command line tools using YAML configuration
139
125
  email: db@dannyben.com
140
126
  executables: