Skip to content

Commit 4206b04

Browse files
committed
- Fix completions library to not show private flags
1 parent 659808a commit 4206b04

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lib/bashly/concerns/completions.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def completion_data(command_full_name)
99
comps = allowed || completions
1010
return {} unless comps
1111

12+
1213
aliases.to_h do |name|
1314
prefix = command_full_name
1415
prefix = "#{prefix}*" unless prefix.end_with? '*'
@@ -62,7 +63,7 @@ def completion_generator
6263
end
6364

6465
def completion_flag_names
65-
flags.map(&:name) + flags.map(&:short)
66+
public_flags.map(&:name) + public_flags.map(&:short)
6667
end
6768

6869
def completion_allowed_args

spec/approvals/fixtures/completions-private

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
+ bundle exec bashly add completions_yaml
1+
+ bundle exec bashly add completions_yaml --force
22
created ./completions.yml
33

44
This file can be converted to a completions script using the completely gem.
@@ -13,8 +13,12 @@ private:
1313
- c
1414
- connect
1515
private connect:
16+
- "--force"
1617
- "--help"
18+
- "-f"
1719
- "-h"
1820
private c:
21+
- "--force"
1922
- "--help"
23+
- "-f"
2024
- "-h"

spec/fixtures/workspaces/completions-private/src/bashly.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ commands:
55
- name: connect
66
alias: c
77
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
817
- name: connect-ftp
918
help: Connect via FTP
1019
alias: cf
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
rm -f ./completions.yml
4-
53
set -x
6-
bundle exec bashly add completions_yaml
4+
bundle exec bashly add completions_yaml --force
75
cat completions.yml

0 commit comments

Comments
 (0)