author | František Kučera <franta-hg@frantovo.cz> |
Thu, 21 Apr 2022 00:22:02 +0200 | |
branch | v_0 |
changeset 27 | b679797949e9 |
parent 5 | 165f6162524d |
permissions | -rw-r--r-- |
0
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
# Relational pipes |
5
165f6162524d
introduce HTTPClient wrapper around CURL
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
2 |
# Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info) |
0
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
# |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
# This program is free software: you can redistribute it and/or modify |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
# it under the terms of the GNU General Public License as published by |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
# the Free Software Foundation, version 3 of the License. |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
# |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
# This program is distributed in the hope that it will be useful, |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
# GNU General Public License for more details. |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
# |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
# You should have received a copy of the GNU General Public License |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
_relpipe_tr_http_completion() { |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
local w0 w1 w2 w3 |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
COMPREPLY=() |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
w0=${COMP_WORDS[COMP_CWORD]} |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
w1=${COMP_WORDS[COMP_CWORD-1]} |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
w2=${COMP_WORDS[COMP_CWORD-2]} |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
w3=${COMP_WORDS[COMP_CWORD-3]} |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
DATA_TYPE=( |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
"string" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
"integer" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
"boolean" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
INPUT_ATTRIBUTE_POLICY=( |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
"append" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
"prepend" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
"auto" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
# FIXME: user must type " and then press TAB otherwise the completion is broken due to the : colon |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
# |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
# can be fixed by global modification of environment variable: |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
# COMP_WORDBREAKS=${COMP_WORDBREAKS//:} |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
# but it will affect other completions (where : is a separator) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
# |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
# these functions should help: |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
# _get_comp_words_by_ref -n : cur |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
# __ltrim_colon_completions "$cur" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
# but was not working (despite w0 renamed to cur) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
XMLNS=( |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
"tag:globalcode.info,2018:relpipe" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
"http://www.w3.org/1999/xhtml" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
"http://www.w3.org/2000/svg" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
"http://www.w3.org/2005/Atom" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
"http://docbook.org/ns/docbook" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
if [[ "$w1" == "--relation" && "x$w0" == "x" ]]; then COMPREPLY=("'.*'") |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
elif [[ "$w1" == "--where" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
elif [[ "$w1" == "--xml-attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
elif [[ "$w1" == "--output-attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
elif [[ "$w2" == "--output-attribute" ]]; then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0")) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
elif [[ "$w3" == "--output-attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
elif [[ "$w1" == "--namespace" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
elif [[ "$w2" == "--namespace" ]]; then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0")) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
elif [[ "$w1" == "--input-attributes" ]]; then COMPREPLY=($(compgen -W "${INPUT_ATTRIBUTE_POLICY[*]}" -- "$w0")) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
else |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
OPTIONS=( |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
"--namespace" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
"--relation" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
"--where" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
"--output-attribute" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
"--input-attributes" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
"--xml-attribute" |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
fi |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
} |
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
|
ce520a238309
new project relpipe-tr-http
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
complete -F _relpipe_tr_http_completion relpipe-tr-http |