Generate bash completion for hurl/hurlfmt

This commit is contained in:
Fabrice Reix 2024-02-01 09:07:08 +01:00 committed by hurl-bot
parent b6a5cfcdce
commit f24de186c2
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
4 changed files with 86 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import glob
from option import Option
import generate_source
import generate_man
import generate_completion
import sys
import re
@ -48,6 +49,17 @@ def update_man(option_files: List[str], output_file):
open(output_file, "w").write(new_man)
def generate_completion_files(name: str, option_files: List[str]):
options = sorted(
[Option.parse_file(option_file) for option_file in option_files],
key=lambda option: option.name,
)
output_file = "completions/" + name + "-completion.bash"
src = generate_completion.generate_bash_completion(name, options)
sys.stderr.write("Generate " + output_file + "\n")
open(output_file, "w").write(src + "\n")
def main():
option_files_hurl = get_option_files("docs/spec/options/hurl")
option_files_hurlfmt = get_option_files("docs/spec/options/hurlfmt")
@ -66,6 +78,10 @@ def main():
update_man(option_files_hurl, "docs/manual/hurl.md")
update_man(option_files_hurlfmt, "docs/manual/hurlfmt.md")
# Generate completion files
generate_completion_files("hurl", option_files_hurl)
generate_completion_files("hurlfmt", option_files_hurlfmt)
if __name__ == "__main__":
main()

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""
Generate Completion files
"""
from typing import *
from option import Option
def generate_bash_completion(name: str, options: List[Option]):
available_options = ["--" + option.long for option in options] + [
"--help",
"--version",
]
return (
"# "
+ name
+ """(1) completion -*- shell-script -*-
_"""
+ name
+ """()
{
local cur prev words cword
_init_completion || return
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '"""
+ " ".join(available_options)
+ """' -- "$cur"))
return
fi
} &&
complete -F _"""
+ name
+ " "
+ name
+ """
# ex: filetype=sh
"""
)

View File

@ -0,0 +1,15 @@
# hurl(1) completion -*- shell-script -*-
_hurl()
{
local cur prev words cword
_init_completion || return
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --json --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur"))
return
fi
} &&
complete -F _hurl hurl
# ex: filetype=sh

View File

@ -0,0 +1,15 @@
# hurlfmt(1) completion -*- shell-script -*-
_hurlfmt()
{
local cur prev words cword
_init_completion || return
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--check --color --format --in-place --in --no-color --output --out --standalone --help --version' -- "$cur"))
return
fi
} &&
complete -F _hurlfmt hurlfmt
# ex: filetype=sh