Skip to content

Commit 9a55f6f

Browse files
committed
add enable_completions to settings JSON schema
1 parent 2e631ff commit 9a55f6f

8 files changed

Lines changed: 65 additions & 3 deletions

File tree

‎lib/bashly/views/argument/completion.gtx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@ if allowed
44
> "{{ value }}"
55
end
66
> )
7-
> completion_candidates "$completion_current" "${completion_values[@]}"
7+
if unique
8+
> local completion_value
9+
> for completion_value in "${completion_values[@]}"; do
10+
> if [[ -z "${completion_used_arguments["{{ name }}:$completion_value"]:-}" ]]; then
11+
> completion_candidates "$completion_current" "$completion_value"
12+
> fi
13+
> done
14+
else
15+
> completion_candidates "$completion_current" "${completion_values[@]}"
16+
end
817
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> completion_used_arguments["{{ name }}:$1"]=1

‎lib/bashly/views/command/completion_argument_filter.gtx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
if args.any?(&:unique)
2+
> case "$completion_arg_index" in
3+
args.each_with_index do |arg, index|
4+
next unless arg.unique
5+
6+
> {{ index }})
7+
= arg.render(:completion_filter).indent 4
8+
> ;;
9+
end
10+
> esac
11+
end
12+
113
if args.last.repeatable
214
last_arg_index = args.length - 1
315
> if [[ $completion_arg_index -lt {{ last_arg_index }} ]]; then

‎lib/bashly/views/command/completion_function.gtx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
if args.any?
66
> local completion_arg_index=0
77
end
8+
if args.any?(&:unique)
9+
> local -A completion_used_arguments=()
10+
end
811
> shift
912
>
1013
= render(:completion_word_filter).indent 2

‎schemas/settings.json‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@
190190
],
191191
"default": "always"
192192
},
193+
"enable_completions": {
194+
"title": "enable_completions",
195+
"description": "Whether to include runtime completion functions in the generated script\nhttps://bashly.dev/usage/settings/#enable_completions",
196+
"type": "string",
197+
"enum": [
198+
"development",
199+
"production",
200+
"always",
201+
"never"
202+
],
203+
"default": "never"
204+
},
193205
"enable_view_markers": {
194206
"title": "enable_view_markers",
195207
"description": "Whether to include view marker comments in the generated script\nhttps://bashly.dev/usage/settings/#enable_view_markers",
@@ -306,7 +318,7 @@
306318
"title": "watch latency",
307319
"description": "The latency in seconds for the file system changes watcher\nhttps://bashly.dev/usage/settings/#watch_latency",
308320
"type": "number",
309-
"default": 1
321+
"default": 1.0
310322
},
311323
"usage_colors": {
312324
"title": "usage colors",

‎spec/fixtures/completions/core/examples.yml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root commands:
22
words: ['']
3-
expected: [server, s, config, cfg, deploy, convert]
3+
expected: [server, s, config, cfg, deploy, convert, release]
44

55
root command prefix:
66
words: [s]
@@ -120,6 +120,14 @@ all positional arguments consumed:
120120
words: [convert, one, three, '']
121121
expected: []
122122

123+
unique positional argument:
124+
words: [release, stable, '']
125+
expected: [beta, edge]
126+
127+
unique positional argument prefix:
128+
words: [release, stable, e]
129+
expected: [edge]
130+
123131
private command is not reachable:
124132
words: [internal, '']
125133
expected: []

‎spec/fixtures/completions/core/src/bashly.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ commands:
7777
help: Target document
7878
required: true
7979

80+
- name: release
81+
help: Release to channels
82+
args:
83+
- name: channel
84+
allowed: [stable, beta, edge]
85+
help: Channels to release to
86+
repeatable: true
87+
unique: true
88+
8089
- name: internal
8190
help: Internal command that must not be suggested
8291
private: true

‎support/schema/settings.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ properties:
169169
type: string
170170
enum: *feature_toggles
171171
default: always
172+
enable_completions:
173+
title: enable_completions
174+
description: |-
175+
Whether to include runtime completion functions in the generated script
176+
https://bashly.dev/usage/settings/#enable_completions
177+
type: string
178+
enum: *feature_toggles
179+
default: never
172180
enable_view_markers:
173181
title: enable_view_markers
174182
description: |-

0 commit comments

Comments
 (0)