File tree Expand file tree Collapse file tree 10 files changed +144
-54
lines changed Expand file tree Collapse file tree 10 files changed +144
-54
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,6 @@ assignees: ''
1111
1212### Reproduction steps
1313
14- ### Expected behavior
15-
1614### Actual behavior
15+
16+ ### Expected behavior
Original file line number Diff line number Diff line change @@ -6,24 +6,23 @@ module Bashly
66 module Completions
77 module Flag
88 def completion_data ( command_full_name )
9- result = { }
109 comps = allowed || completions
10+ return { } unless comps
1111
12- if comps
13- aliases . each do | name |
14- result [ "#{ command_full_name } * #{ name } " ] = comps
15- end
12+ aliases . to_h do | name |
13+ prefix = command_full_name
14+ prefix = "#{ prefix } *" unless prefix . end_with? '*'
15+ [ " #{ prefix } #{ name } " , comps ]
1616 end
17-
18- result
1917 end
2018 end
2119
2220 module Command
2321 def completion_data ( with_version : true )
2422 result = { }
2523
26- all_full_names . each do |name |
24+ completion_full_names . each do |name |
25+ name = "#{ name } *" if name . include? '*'
2726 result [ name ] = completion_words with_version : with_version
2827 flags . each do |flag |
2928 result . merge! flag . completion_data ( name )
@@ -45,6 +44,17 @@ def completion_function(name = nil)
4544 completion_generator . wrapper_function name
4645 end
4746
47+ protected
48+
49+ def completion_full_names
50+ if parent_command
51+ glue = parent_command . global_flags? ? '*' : ' '
52+ parent_command . completion_full_names . product ( aliases ) . map { |a | a . join glue }
53+ else
54+ aliases
55+ end
56+ end
57+
4858 private
4959
5060 def completion_generator
Original file line number Diff line number Diff line change @@ -34,16 +34,6 @@ def aliases
3434 [ name ] + alt
3535 end
3636
37- # Returns an array of all full names (including aliases and aliases of
38- # parents)
39- def all_full_names
40- if parent_command
41- parent_command . all_full_names . product ( aliases ) . map { |a | a . join ' ' }
42- else
43- aliases
44- end
45- end
46-
4737 # Returns an array of alternative aliases if any
4838 def alt
4939 # DEPRECATION 0.8.0
Original file line number Diff line number Diff line change 1+ ---
2+ cli:
3+ - "--debug"
4+ - "--help"
5+ - "--version"
6+ - "-h"
7+ - "-v"
8+ - images
9+ cli*images*:
10+ - "--help"
11+ - "--verbose"
12+ - "-h"
13+ - ls
14+ cli*images*ls*:
15+ - "--env"
16+ - "--help"
17+ - "-h"
18+ cli*images*ls*--env:
19+ - prod
20+ - dev
Original file line number Diff line number Diff line change 1+ ---
2+ cli:
3+ - "--help"
4+ - "--version"
5+ - "-h"
6+ - "-v"
7+ - images
8+ cli images:
9+ - "--help"
10+ - "--verbose"
11+ - "-h"
12+ - ls
13+ cli images*ls*:
14+ - "--help"
15+ - "-h"
Original file line number Diff line number Diff line change 1+ ---
2+ cli:
3+ - "--debug"
4+ - "--help"
5+ - "--version"
6+ - "-h"
7+ - "-v"
8+ - images
9+ cli*images*:
10+ - "--help"
11+ - "-h"
12+ - ls
13+ cli*images ls*:
14+ - "--env"
15+ - "--help"
16+ - "-h"
17+ cli*images ls*--env:
18+ - prod
19+ - dev
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 5959 end
6060 end
6161 end
62+
63+ context 'with a command that has global flags on the root command' do
64+ let ( :fixture ) { :completions_global_flags_root }
65+
66+ describe '#completion_data' do
67+ it 'returns a data structure that includes all command full names' do
68+ expect ( subject . completion_data . to_yaml )
69+ . to match_approval ( 'completions/completion_global_flags_root' )
70+ end
71+ end
72+ end
73+
74+ context 'with a command that has global flags on a nested command' do
75+ let ( :fixture ) { :completions_global_flags_nested }
76+
77+ describe '#completion_data' do
78+ it 'returns a data structure that includes all command full names' do
79+ expect ( subject . completion_data . to_yaml )
80+ . to match_approval ( 'completions/completion_global_flags_nested' )
81+ end
82+ end
83+ end
84+
85+ context 'with a command that has global flags on the root and a nested command' do
86+ let ( :fixture ) { :completions_global_flags }
87+
88+ describe '#completion_data' do
89+ it 'returns a data structure that includes all command full names' do
90+ expect ( subject . completion_data . to_yaml )
91+ . to match_approval ( 'completions/completion_global_flags' )
92+ end
93+ end
94+ end
6295end
Original file line number Diff line number Diff line change 5050 end
5151 end
5252
53- describe '#all_full_names' do
54- let ( :fixture ) { :nested_aliases }
55-
56- it 'returns an array of all full names including aliases' do
57- expect ( subject . deep_commands . last . all_full_names . to_yaml )
58- . to match_approval ( 'script/command/nested_aliases' )
59- end
60- end
61-
6253 describe '#args' do
6354 it 'returns an array of Argument objects' do
6455 expect ( subject . args ) . to be_an Array
Original file line number Diff line number Diff line change 9898 arg : name
9999 allowed : [get, post]
100100
101+ :completions_global_flags :
102+ name : cli
103+ flags :
104+ - long : --debug
105+ commands :
106+ - name : images
107+ flags :
108+ - long : --verbose
109+ commands :
110+ - name : ls
111+ flags :
112+ - long : --env
113+ arg : env
114+ allowed : [prod, dev]
115+
116+ :completions_global_flags_nested :
117+ name : cli
118+ commands :
119+ - name : images
120+ flags :
121+ - long : --verbose
122+ commands :
123+ - name : ls
124+
125+ :completions_global_flags_root :
126+ name : cli
127+ flags :
128+ - long : --debug
129+ commands :
130+ - name : images
131+ commands :
132+ - name : ls
133+ flags :
134+ - long : --env
135+ arg : env
136+ allowed : [prod, dev]
137+
101138:custom_filename :
102139 name : run
103140 filename : ops/run_command.sh
You can’t perform that action at this time.
0 commit comments