Skip to content

Commit 300b936

Browse files
yedayakscop
authored andcommitted
feat(openssl): Stop having subcommands hardcoded
Instead we get the command list by parsing openssl help, which also adds some subcommands that were missing, and removes some non-existant ones (at least on versions I have). The parsing only happens when it's necessary, when the subcommand wasn't chosen.
1 parent df48031 commit 300b936

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

completions/openssl

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,11 @@ _comp_cmd_openssl()
4242
local cur prev words cword comp_args
4343
_comp_initialize -- "$@" || return
4444

45-
local commands command formats
46-
47-
commands='asn1parse ca ciphers crl crl2pkcs7 dgst dh dhparam dsa dsaparam
48-
ec ecparam enc engine errstr gendh gendsa genrsa nseq ocsp passwd
49-
pkcs12 pkcs7 pkcs8 prime rand req rsa rsautl s_client s_server s_time
50-
sess_id smime speed spkac storeutl verify version x509 md2 md4 md5 rmd160
51-
sha sha1 aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc
52-
aes-256-ecb base64 bf bf-cbc bf-cfb bf-ecb bf-ofb camellia-128-cbc
53-
camellia-128-ecb camellia-192-cbc camellia-192-ecb camellia-256-cbc
54-
camellia-256-ecb cast cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb
55-
des des-cbc des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb des-ede-ofb
56-
des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb des-ofb des3 desx rc2
57-
rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb rc4 rc4-40
58-
sha224 sha256 sha384 sha512 genpkey pkey pkeyparam pkeyutl'
45+
local command formats
5946

6047
if ((cword == 1)); then
48+
local commands
49+
commands="$("$1" help 2>&1 | command sed -e '/commands\|help:/d')"
6150
_comp_compgen -- -W "$commands"
6251
else
6352
command=${words[1]}

test/t/test_openssl.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33

44
class TestOpenssl:
5-
@pytest.mark.complete("openssl ")
5+
@pytest.mark.complete("openssl ", require_cmd=True)
66
def test_1(self, completion):
77
assert completion
8+
assert all(
9+
x in completion for x in "md5 x509 aes-128-cbc dgst pkey".split()
10+
)
811

912
@pytest.mark.complete("openssl pkey -cipher ", require_cmd=True)
1013
def test_2(self, completion):

0 commit comments

Comments
 (0)