forked from killbill/kbcli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfind-swagger.sh
executable file
·73 lines (63 loc) · 2.04 KB
/
find-swagger.sh
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
#!/bin/bash
# Colors
RED='\033[0;31m'
NC='\033[0m' # No Color
current_dir=$(pwd)
original_dir=$current_dir
# Determine the "github.com" or equivalent directory for cloning
base_repo_dir=$(basename $(dirname $(dirname "$original_dir")))
# Define the directories for the search
parent_dir=$(dirname "$original_dir")
grandparent_dir=$(dirname "$parent_dir")
# We'll also define the use_directory function to avoid repetition:
use_directory() {
local dir=$1
cd "$dir"
make bindata
make swagger
echo "$dir" > "$original_dir/.found-swagger-path"
}
# Search in the immediate parent directory
if [ -d "$parent_dir/go-swagger" ]; then
read -p "Use this path: $parent_dir/go-swagger? [y/N]: " response
if [ "$response" = "y" ]; then
use_directory "$parent_dir/go-swagger"
fi
exit 0
fi
# Check the grandparent directory
if [ -d "$grandparent_dir/go-swagger" ]; then
read -p "Use this path: $grandparent_dir/go-swagger? [y/N]: " response
if [ "$response" = "y" ]; then
use_directory "$grandparent_dir/go-swagger"
fi
exit 0
fi
# If not found in either, loop through each subdirectory of the grandparent directory
for subdir in "$grandparent_dir"/*; do
if [ -d "$subdir/go-swagger" ]; then
read -p "Use this path: $subdir/go-swagger? [y/N]: " response
if [ "$response" = "y" ]; then
use_directory "$subdir/go-swagger"
exit 0
fi
fi
done
# If not found, attempt to clone
repo_base=$(basename $(dirname "$original_dir"))
clone_dest=$(dirname "$original_dir")/go-swagger
read -p "Attempt to clone from https://$base_repo_dir/$repo_base/go-swagger? [y/N]: " response
if [ "$response" = "y" ]; then
git clone "https://$base_repo_dir/$repo_base/go-swagger" "$clone_dest"
if [ ! -d "$clone_dest" ]; then
printf "${RED}Error:${NC} Failed to clone go-swagger!\n"
exit 1
fi
cd "$clone_dest"
make bindata
make swagger
echo "$clone_dest" > .found-swagger-path
else
printf "${RED}Error:${NC} go-swagger not found!\n"
exit 1
fi