Skip to content

Commit 4e0c77c

Browse files
[Refactor] - refactor aws_get_command to reuse function curl
1 parent fd0b9c0 commit 4e0c77c

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

services/help.sh

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,17 @@ aws_main_function() {
3030
# }
3131

3232
aws_get_command() {
33-
# function curl_aws_document_and_cut() {
34-
# echo "curl_aws_document_and_cut $1"
35-
# local aws_service_name=$1
36-
# local curl_path=$([ -z "$aws_service_name" ] && echo "index.html" || echo "reference/$aws_service/index.html" )
37-
# curl -s "https://awscli.amazonaws.com/v2/documentation/api/latest/reference/${curl_path}" \
38-
# | grep '<li class="toctree-l1"><a class="reference internal"' \
39-
# | awk -F '.html">' '{print $2}' \
40-
# | awk -F '</a>' '{print $1}' > ${aws_cli_input_folder}/aws_list_services.txt
41-
# }
33+
function curl_aws_document_and_cut() {
34+
local aws_service_name=$1
35+
local curl_path=$([ -z "$aws_service_name" ] && echo "index.html" || echo "$aws_service/index.html" )
36+
curl -s "https://awscli.amazonaws.com/v2/documentation/api/latest/reference/${curl_path}" \
37+
| grep '<li class="toctree-l1"><a class="reference internal"' \
38+
| awk -F '.html">' '{print $2}' \
39+
| awk -F '</a>' '{print $1}'
40+
}
4241

4342
if [ ! -s ${aws_cli_input_folder}/aws_list_services.txt ]; then
44-
curl -s https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html \
45-
| grep '<li class="toctree-l1"><a class="reference internal"' \
46-
| awk -F '.html">' '{print $2}' \
47-
| awk -F '</a>' '{print $1}' > ${aws_cli_input_folder}/aws_list_services.txt
43+
curl_aws_document_and_cut > ${aws_cli_input_folder}/aws_list_services.txt
4844
fi
4945

5046
local aws_service=$(cat ${aws_cli_input_folder}/aws_list_services.txt | peco --prompt "Select service >")
@@ -54,10 +50,7 @@ aws_get_command() {
5450
fi
5551

5652
if [ ! -s ${aws_cli_list_commands_folder}/aws_service.txt ]; then
57-
curl -s https://awscli.amazonaws.com/v2/documentation/api/latest/reference/$aws_service/index.html \
58-
| grep '<li class="toctree-l1"><a class="reference internal"' \
59-
| awk -F '.html">' '{print $2}' \
60-
| awk -F '</a>' '{print $1}' > ${aws_cli_list_commands_folder}/$aws_service.txt
53+
curl_aws_document_and_cut "$aws_service" > ${aws_cli_list_commands_folder}/$aws_service.txt
6154
fi
6255

6356
local aws_command=$(cat ${aws_cli_list_commands_folder}/$aws_service.txt | peco --prompt "aws $aws_service" --on-cancel error)

0 commit comments

Comments
 (0)