Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate bash completion for hurl/hurlfmt #2452

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bin/spec/options/generate_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from option import Option
import generate_source
import generate_man
import generate_completion
import sys
import re

Expand Down Expand Up @@ -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")
Expand All @@ -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()
40 changes: 40 additions & 0 deletions bin/spec/options/generate_completion.py
Original file line number Diff line number Diff line change
@@ -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
"""
)
15 changes: 15 additions & 0 deletions completions/hurl-completion.bash
Original file line number Diff line number Diff line change
@@ -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

15 changes: 15 additions & 0 deletions completions/hurlfmt-completion.bash
Original file line number Diff line number Diff line change
@@ -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

Loading