File tree Expand file tree Collapse file tree 10 files changed +99
-3
lines changed
workspaces/completions-private Expand file tree Collapse file tree 10 files changed +99
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ Metrics/PerceivedComplexity: { Exclude: [lib/bashly/config_validator.rb] }
19
19
Metrics/MethodLength : { Exclude: [lib/bashly/config_validator.rb] }
20
20
Style/GuardClause : { Exclude: [lib/bashly/config_validator.rb] }
21
21
22
+ # FIXME: The `Command` class is too long
23
+ Metrics/ClassLength : { Exclude: [lib/bashly/script/command.rb] }
24
+
22
25
# Allow irregular filenames in some cases
23
26
RSpec/FilePath :
24
27
Exclude :
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def completion_data(with_version: true)
29
29
end
30
30
end
31
31
32
- commands . each do |command |
32
+ public_commands . each do |command |
33
33
result . merge! command . completion_data ( with_version : false )
34
34
end
35
35
@@ -62,7 +62,7 @@ def completion_generator
62
62
end
63
63
64
64
def completion_flag_names
65
- flags . map ( &:name ) + flags . map ( &:short )
65
+ public_flags . map ( &:name ) + public_flags . map ( &:short )
66
66
end
67
67
68
68
def completion_allowed_args
@@ -73,7 +73,7 @@ def completion_words(with_version: false)
73
73
trivial_flags = %w[ --help -h ]
74
74
trivial_flags += %w[ --version -v ] if with_version
75
75
all = (
76
- command_aliases + trivial_flags +
76
+ public_command_aliases + trivial_flags +
77
77
completion_flag_names + completion_allowed_args
78
78
)
79
79
Original file line number Diff line number Diff line change @@ -223,6 +223,11 @@ def public_commands
223
223
commands . reject ( &:private )
224
224
end
225
225
226
+ # Returns a full list of the public Command names and aliases combined
227
+ def public_command_aliases
228
+ public_commands . map ( &:aliases ) . flatten
229
+ end
230
+
226
231
# Returns only environment variables that are not private
227
232
def public_environment_variables
228
233
environment_variables . reject ( &:private )
Original file line number Diff line number Diff line change
1
+ + bundle exec bashly add completions_yaml --force
2
+ created ./completions.yml
3
+
4
+ This file can be converted to a completions script using the completely gem.
5
+
6
+ + cat completions.yml
7
+ ---
8
+ private:
9
+ - "--help"
10
+ - "--version"
11
+ - "-h"
12
+ - "-v"
13
+ - c
14
+ - connect
15
+ private connect:
16
+ - "--force"
17
+ - "--help"
18
+ - "-f"
19
+ - "-h"
20
+ private c:
21
+ - "--force"
22
+ - "--help"
23
+ - "-f"
24
+ - "-h"
Original file line number Diff line number Diff line change 339
339
end
340
340
end
341
341
342
+ describe '#public_commands' do
343
+ let ( :fixture ) { :private_commands }
344
+
345
+ it 'returns an array of Command objects excluding private commands' do
346
+ expect ( subject . public_commands . count ) . to eq 1
347
+ expect ( subject . public_commands . first . name ) . to eq 'connect'
348
+ end
349
+ end
350
+
351
+ describe '#public_commands_aliases' do
352
+ let ( :fixture ) { :private_commands }
353
+
354
+ it 'returns an array of command aliases of public subcommands' do
355
+ expect ( subject . public_command_aliases ) . to eq %w[ connect c ]
356
+ end
357
+ end
358
+
342
359
describe '#user_file_path' do
343
360
it 'returns the path to the user file' do
344
361
expect ( subject . user_file_path 'test.sh' ) . to eq 'spec/tmp/src/test.sh'
Original file line number Diff line number Diff line change 378
378
short : -c
379
379
allowed : [green, red]
380
380
381
+ :private_commands :
382
+ name : private
383
+ help : Test private commands
384
+ commands :
385
+ - name : connect
386
+ alias : c
387
+ - name : connect-ftp
388
+ alias : cf
389
+ private : true
390
+ - name : connect-ssh
391
+ alias : cf
392
+ private : true
393
+
381
394
:repeatable_arg :
382
395
name : get
383
396
args :
Original file line number Diff line number Diff line change
1
+ completions.yml
Original file line number Diff line number Diff line change
1
+ This fixture tests that private commands and flags are not added to the
2
+ generated completions scripts.
3
+
4
+ Reference issue: https://github.com/DannyBen/bashly/issues/388
Original file line number Diff line number Diff line change
1
+ name : private
2
+ help : Test private commands
3
+
4
+ commands :
5
+ - name : connect
6
+ alias : c
7
+ help : Connect to the metaverse
8
+ flags :
9
+ - long : --force
10
+ short : -f
11
+ # Private flag below - should not be present in completions
12
+ - long : --hidden-flag
13
+ short : -d
14
+ private : true
15
+
16
+ # Private commands below - should not be present in completions
17
+ - name : connect-ftp
18
+ help : Connect via FTP
19
+ alias : cf
20
+ private : true
21
+ - name : connect-ssh
22
+ help : Connect via SSH
23
+ alias : cs
24
+ private : true
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ set -x
4
+ bundle exec bashly add completions_yaml --force
5
+ cat completions.yml
You can’t perform that action at this time.
0 commit comments