summaryrefslogtreecommitdiffstats
path: root/extras/completion/completion.zsh
blob: a482668a8e8a4a8c67ba02c3c9a4fab5d4bb444e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#compdef http
# Copyright (c) 2015 Github zsh-users
# Based on the initial work of http://github.com/zsh-users

METHODS=("GET" "POST" "PUT" "DELETE" "HEAD" "OPTIONS" "PATCH" "TRACE" "CONNECT" )

_httpie_params () {
    local ret=1 expl
    local current=$words[$CURRENT]
    if (( CURRENT > NORMARG )); then
        local predecessor=$words[(( $CURRENT - 1 ))]
    fi

    if ! [[ $current == -* ]]; then
        if (( CURRENT == NORMARG + 0 )); then
            _httpie_method && ret=0
        fi
        if (( CURRENT == NORMARG + 0 )); then
            _httpie_url && ret=0
        fi
        if (( CURRENT == NORMARG + 1 )) && [[ ${METHODS[(ie)$predecessor]} -le ${#METHODS} ]]; then
            _httpie_url && ret=0
        fi
        if (( CURRENT >= NORMARG + 2 )); then
            _httpie_request_item && ret=0
        fi
        if (( CURRENT >= NORMARG + 1 )) && ! [[ ${METHODS[(ie)$predecessor]} -le ${#METHODS} ]]; then
            _httpie_request_item && ret=0
        fi
        
    fi

    return $ret

}

_httpie_request_item() {
    compset -P '(#b)([^:@=]#)'
    local name=$match[1]

    if false; then
        false;
    elif compset -P ':'; then
        _message "$name HTTP Headers"
        
    elif compset -P '=='; then
        _message "$name URL Parameters"
        
    elif compset -P '='; then
        _message "$name Data Fields"
        
    elif compset -P ':='; then
        _message "$name Raw JSON Fields"
        
    elif compset -P '@'; then
        _files
        
    else
        typeset -a ops
        ops=(
            "\::Arbitrary HTTP header, e.g X-API-Token:123"
            "==:Querystring parameter to the URL, e.g limit==50"
            "=:Data fields to be serialized as JSON (default) or Form Data (with --form)"
            "\:=:Data field for real JSON types."
            "@:Path field for uploading a file."
            )
        _describe -t httpparams 'parameter types' ops -Q -S ''
    fi
    return 1;
}

_httpie_method() {
    _wanted http_method expl 'Request Method' \
            compadd GET POST PUT DELETE HEAD OPTIONS PATCH TRACE CONNECT && ret=0
    return 1;
}

_httpie_url() {
    local ret=1

    if ! [[ -prefix [-+.a-z0-9]#:// ]]; then
        local expl
        compset -S '[^:/]*' && compstate[to_end]=''
        _wanted url-schemas expl 'URL schema' compadd -S '' http:// https:// && ret=0
    else
        _urls && ret=0
    fi

    return $ret
}

integer NORMARG

_arguments -n -C -s \
    {--json,-j}'[(default) Serialize data items from the command line as a JSON object.]' \
    {--form,-f}'[Serialize data items from the command line as form field data.]' \
    '--multipart[Similar to --form, but always sends a multipart/form-data request (i.e., even without files).]' \
    '--boundary=[Specify a custom boundary string for multipart/form-data requests. Only has effect only together with --form.]' \
    '--raw=[Pass raw request data without extra processing.]' \
    {--compress,-x}'[Compress the content with Deflate algorithm.]' \
    '--pretty=[Control the processing of console outputs.]:PRETTY:(all colors format none)' \
    {--style,-s}'=[Output coloring style (default is "auto").]:STYLE:' \
    '--unsorted[Disables all sorting while formatting output.]' \
    '--sorted[Re-enables all sorting options while formatting output.]' \
    '--response-charset=[Override the response encoding for terminal display purposes.]:ENCODING:' \
    '--response-mime=[Override the response mime type for coloring and formatting for the terminal.]:MIME_TYPE:' \
    '--format-options=[Controls output formatting.]' \
    {--print,-p}'=[Options to specify what the console output should contain.]:WHAT:' \
    {--headers,-h}'[Print only the response headers.]' \
    {--meta,-m}'[Print only the response metadata.]' \
    {--body,-b}'[Print only the response body.]' \
    {--verbose,-v}'[Make output more verbose.]' \
    '--all[Show any intermediary requests/responses.]' \
    {--stream,-S}'[Always stream the response body by line, i.e., behave like `tail -f`.]' \
    {--output,-o}'=[Save output to FILE instead of stdout.]:FILE:' \
    {--download,-d}'[Download the body to a file instead of printing it to stdout.]' \
    {--continue,-c}'[Resume an interrupted download (--output needs to be specified).]' \
    {--quiet,-q}'[Do not print to stdout or stderr, except for errors and warnings when provided once.]' \
    '--session=[Create, or reuse and update a session.]:SESSION_NAME_OR_PATH:' \
    '--session-read-only=[Create or read a session without updating it]:SESSION_NAME_OR_PATH:' \
    {--auth,-a}'=[Credentials for the selected (-A) authentication method.]:USER[\:PASS] | TOKEN:' \
    {--auth-type,-A}'=[The authentication mechanism to be used.]' \
    '--ignore-netrc[Ignore credentials from .netrc.]' \
    '--offline[Build the request and print it but don’t actually send it.]' \
    '--proxy=[String mapping of protocol to the URL of the proxy.]:PROTOCOL\:PROXY_URL:' \
    {--follow,-F}'[Follow 30x Location redirects.]' \
    '--max-redirects=[The maximum number of redirects that should be followed (with --follow).]' \
    '--max-headers=[The maximum number of response headers to be read before giving up (default 0, i.e., no limit).]' \
    '--timeout=[The connection timeout of the request in seconds.]:SECONDS:' \
    '--check-status[Exit with an error status code if the server replies with an error.]' \
    '--path-as-is[Bypass dot segment (/../ or /./) URL squashing.]' \
    '--chunked[Enable streaming via chunked transfer encoding. The Transfer-Encoding header is set to chunked.]' \
    '--verify=[If "no", skip SSL verification. If a file path, use it as a CA bundle.]' \
    '--ssl=[The desired protocol version to used.]:SSL:(ssl2.3 tls1 tls1.1 tls1.2)' \
    '--ciphers=[A string in the OpenSSL cipher list format.]' \
    '--cert=[Specifys a local cert to use as client side SSL certificate.]' \
    '--cert-key=[The private key to use with SSL. Only needed if --cert is given.]' \
    '--cert-key-pass=[The passphrase to be used to with the given private key.]' \
    {--ignore-stdin,-I}'[Do not attempt to read stdin]' \
    '--help[Show this help message and exit.]' \
    '--manual[Show the full manual.]' \
    '--version[Show version and exit.]' \
    '--traceback[Prints the exception traceback should one occur.]' \
    '--default-scheme=[The default scheme to use if not specified in the URL.]' \
    '--debug[Print useful diagnostic information for bug reports.]' \
    '*:args:_httpie_params' && return 0