Generate zsh completion for hurl/hurlfmt

This commit is contained in:
Fabrice Reix 2024-02-28 09:11:28 +01:00 committed by hurl-bot
parent 7128eb7456
commit e52ccdcb93
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
4 changed files with 202 additions and 0 deletions

View File

@ -60,6 +60,11 @@ def generate_completion_files(name: str, option_files: List[str]):
sys.stderr.write("Generate " + output_file + "\n")
open(output_file, "w").write(src + "\n")
output_file = "completions/_" + name
src = generate_completion.generate_zsh_completion(name, options)
sys.stderr.write("Generate " + output_file + "\n")
open(output_file, "w").write(src + "\n")
output_file = "completions/_" + name + ".ps1"
src = generate_completion.generate_powershell_completion(name, options)
sys.stderr.write("Generate " + output_file + "\n")

View File

@ -40,6 +40,76 @@ _"""
)
def generate_zsh_completion(name: str, options: List[Option]):
return (
"""#compdef """
+ name
+ """
autoload -U is-at-least
_"""
+ name
+ """() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
"""
+ """\n """.join([zsh_option(option) for option in options])
+ """
'--help[Print help]' \
'--version[Print version]' \
'*::params:' \\
&& ret=0
}
(( $+functions[_"""
+ name
+ """_commands] )) ||
_"""
+ name
+ """_commands() {
local commands; commands=()
_describe -t commands '"""
+ name
+ """ commands' commands "$@"
}
if [ "$funcstack[1]" = "_"""
+ name
+ """" ]; then
_"""
+ name
+ """ "$@"
else
compdef _"""
+ name
+ " "
+ name
+ """
fi"""
)
def zsh_option(option: Option):
return (
"'--"
+ option.long
+ "["
+ option.help.replace("[", "\[").replace("]", "\]")
+ "]: : ' \\"
)
def generate_powershell_completion(name: str, options: List[Option]):
return (
"""using namespace System.Management.Automation

87
completions/_hurl Normal file
View File

@ -0,0 +1,87 @@
#compdef hurl
autoload -U is-at-least
_hurl() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" '--aws-sigv4[Use AWS V4 signature authentication in the transfer]: : ' \
'--cacert[CA certificate to verify peer against (PEM format)]: : ' \
'--cert[Client certificate file and password]: : ' \
'--key[Private key file name]: : ' \
'--color[Colorize output]: : ' \
'--compressed[Request compressed response (using deflate or gzip)]: : ' \
'--connect-timeout[Maximum time allowed for connection]: : ' \
'--connect-to[For a request to the given HOST1:PORT1 pair, connect to HOST2:PORT2 instead]: : ' \
'--continue-on-error[Continue executing requests even if an error occurs]: : ' \
'--cookie[Read cookies from FILE]: : ' \
'--cookie-jar[Write cookies to FILE after running the session (only for one session)]: : ' \
'--delay[Sets delay before each request.]: : ' \
'--error-format[Control the format of error messages]: : ' \
'--fail-at-end[Fail at end]: : ' \
'--file-root[Set root directory to import files \[default: current directory\]]: : ' \
'--location[Follow redirects]: : ' \
'--location-trusted[Follow redirects but allows sending the name + password to all hosts that the site may redirect to.]: : ' \
'--glob[Specify input files that match the given GLOB. Multiple glob flags may be used]: : ' \
'--http1.0[Tell Hurl to use HTTP version 1.0]: : ' \
'--http1.1[Tell Hurl to use HTTP version 1.1]: : ' \
'--http2[Tell Hurl to use HTTP version 2]: : ' \
'--http3[Tell Hurl to use HTTP version 3]: : ' \
'--ignore-asserts[Ignore asserts defined in the Hurl file]: : ' \
'--include[Include the HTTP headers in the output]: : ' \
'--insecure[Allow insecure SSL connections]: : ' \
'--interactive[Turn on interactive mode]: : ' \
'--ipv4[Tell Hurl to use IPv4 addresses only when resolving host names, and not for example try IPv6]: : ' \
'--ipv6[Tell Hurl to use IPv6 addresses only when resolving host names, and not for example try IPv4]: : ' \
'--json[Output each Hurl file result to JSON]: : ' \
'--max-redirs[Maximum number of redirects allowed, -1 for unlimited redirects]: : ' \
'--max-time[Maximum time allowed for the transfer]: : ' \
'--netrc[Must read .netrc for username and password]: : ' \
'--netrc-file[Specify FILE for .netrc]: : ' \
'--netrc-optional[Use either .netrc or the URL]: : ' \
'--no-color[Do not colorize output]: : ' \
'--no-output[Suppress output. By default, Hurl outputs the body of the last response]: : ' \
'--noproxy[List of hosts which do not use proxy]: : ' \
'--output[Write to FILE instead of stdout]: : ' \
'--path-as-is[Tell Hurl to not handle sequences of /../ or /./ in the given URL path]: : ' \
'--proxy[Use proxy on given PROTOCOL/HOST/PORT]: : ' \
'--report-html[Generate HTML report to DIR]: : ' \
'--report-junit[Write a JUnit XML report to FILE]: : ' \
'--report-tap[Write a TAP report to FILE]: : ' \
'--resolve[Provide a custom address for a specific HOST and PORT pair]: : ' \
'--retry[Maximum number of retries, 0 for no retries, -1 for unlimited retries]: : ' \
'--retry-interval[Interval in milliseconds before a retry]: : ' \
'--ssl-no-revoke[(Windows) Tell Hurl to disable certificate revocation checks. WARNING: this option loosens the SSL security, and by using this flag you ask for exactly that.]: : ' \
'--test[Activate test mode]: : ' \
'--to-entry[Execute Hurl file to ENTRY_NUMBER (starting at 1)]: : ' \
'--unix-socket[(HTTP) Connect through this Unix domain socket, instead of using the network]: : ' \
'--user[Add basic Authentication header to each request]: : ' \
'--user-agent[Specify the User-Agent string to send to the HTTP server]: : ' \
'--variable[Define a variable]: : ' \
'--variables-file[Define a properties file in which you define your variables]: : ' \
'--verbose[Turn on verbose]: : ' \
'--very-verbose[Turn on verbose output, including HTTP response and libcurl logs]: : ' \
'--help[Print help]' '--version[Print version]' '*::params:' \
&& ret=0
}
(( $+functions[_hurl_commands] )) ||
_hurl_commands() {
local commands; commands=()
_describe -t commands 'hurl commands' commands "$@"
}
if [ "$funcstack[1]" = "_hurl" ]; then
_hurl "$@"
else
compdef _hurl hurl
fi

40
completions/_hurlfmt Normal file
View File

@ -0,0 +1,40 @@
#compdef hurlfmt
autoload -U is-at-least
_hurlfmt() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
if is-at-least 5.2; then
_arguments_options=(-s -S -C)
else
_arguments_options=(-s -C)
fi
local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" '--check[Run in 'check' mode]: : ' \
'--color[Colorize Output]: : ' \
'--format[Specify output format: hurl, json or html]: : ' \
'--in-place[Modify files in place]: : ' \
'--in[Specify input format: hurl or curl]: : ' \
'--no-color[Do not colorize output]: : ' \
'--output[Write to FILE instead of stdout]: : ' \
'--out[Specify output format: hurl, json or html]: : ' \
'--standalone[Standalone HTML]: : ' \
'--help[Print help]' '--version[Print version]' '*::params:' \
&& ret=0
}
(( $+functions[_hurlfmt_commands] )) ||
_hurlfmt_commands() {
local commands; commands=()
_describe -t commands 'hurlfmt commands' commands "$@"
}
if [ "$funcstack[1]" = "_hurlfmt" ]; then
_hurlfmt "$@"
else
compdef _hurlfmt hurlfmt
fi