@@ -6,38 +6,62 @@ RED='\033[0;31m'
6
6
GREEN=' \033[0;32m'
7
7
NC=' \033[0m'
8
8
9
- readonly brain_dir =" $HOME /.brain"
9
+ readonly BRAIN_DIR =" $HOME /.brain"
10
10
readonly VERSION_FILE=" $HOME /.brain/version"
11
- readonly _brain_bin =" /usr/local/bin/brain"
12
- readonly neurons_git =" https://raw.githubusercontent.com/neobrains/brain/main/neurons"
13
- readonly brain_url =" https://raw.githubusercontent.com/neobrains/brain/main/brain.sh "
11
+ readonly _BRAIN_BIN =" /usr/local/bin/brain"
12
+ readonly NEURONS_GIT =" https://raw.githubusercontent.com/neobrains/brain/main/neurons"
13
+ readonly RAW_URI =" https://raw.githubusercontent.com/neobrains/brain/main"
14
14
15
15
valid_commands=(" install" " uninstall" " update" " upgrade" " search" " list" " info" )
16
16
17
17
usage () {
18
+ declare -A options
19
+ options[" -h, --help" ]=" Show this help message and exit"
20
+ options[" -v, --version" ]=" Show version and exit"
21
+ options[" -u, --upgrade" ]=" Update brain to the latest version"
22
+ options[" -f, --force" ]=" Force update brain to the latest version"
23
+ options[" -r, --remove" ]=" Remove brain from your system"
24
+
25
+ declare -A commands
26
+ commands[" install" ]=" Install a package"
27
+ commands[" uninstall" ]=" Uninstall a package"
28
+ commands[" update" ]=" Update a package"
29
+ commands[" neurons" ]=" List (local / remote) / search / info about packages"
30
+
18
31
echo " Usage: $( basename " $0 " ) [options] [command]"
19
32
echo " brain version $( cat " $VERSION_FILE " ) "
20
33
echo " Options:"
21
- echo " -h, --help Show this help message and exit "
22
- echo " -v, --version Show version and exit "
23
- echo " -u, --upgrade Update brain to the latest version "
24
- echo " -f, --force Force update brain to the latest version "
25
- echo " -r, --remove Remove brain from your system "
34
+
35
+ for opt in " ${ ! options[@]} " ; do
36
+ printf " %-20s %s\n " " $opt " " ${options[$opt]} "
37
+ done
38
+
26
39
echo " Commands:"
27
- echo " install Install a package"
28
- echo " uninstall Uninstall a package"
29
- echo " update Update a package"
30
- echo " neurons List (local / remote) / search / info about packages"
40
+
41
+ for cmd in " ${! commands[@]} " ; do
42
+ printf " %-20s %s\n" " $cmd " " ${commands[$cmd]} "
43
+ done
44
+
31
45
echo " "
32
46
echo " For more information, visit https://github.com/neobrains/brain"
33
47
}
34
48
35
49
neurons_usage () {
36
- echo " Usage: $( basename " $0 " ) [options] [command]"
50
+ declare -A commands
51
+
52
+ commands[" list remote" ]=" List all available packages"
53
+ commands[" list local" ]=" List locally installed packages"
54
+ commands[" info" ]=" Show information about a package"
55
+
56
+ declare -r script_name=$( basename " $0 " )
57
+
58
+ echo " Usage: $script_name [options] [command]"
37
59
echo " Commands:"
38
- echo " list remote List all available packages"
39
- echo " list local List locally installed packages"
40
- echo " info Show information about a package"
60
+
61
+ for cmd in " ${! commands[@]} " ; do
62
+ printf " %-15s %s\n" " $cmd " " ${commands[$cmd]} "
63
+ done
64
+
41
65
echo " "
42
66
echo " For more information, visit https://github.com/neobrains/brain"
43
67
}
@@ -68,10 +92,10 @@ if [[ $1 =~ (-u|--upgrade) ]]; then
68
92
update_brain () {
69
93
echo " Updating brain..."
70
94
check_sudo
71
- curl -fsSL -o brain $brain_url
95
+ curl -fsSL -o brain " ${RAW_URI} /brain.sh "
72
96
chmod +x brain
73
- if [ ! -d " $brain_dir " ]; then
74
- mkdir " $brain_dir "
97
+ if [ ! -d " $BRAIN_DIR " ]; then
98
+ mkdir " $BRAIN_DIR "
75
99
fi
76
100
latest_version=$( curl -s https://api.github.com/repos/neobrains/brain/releases/latest | jq -r ' .tag_name' )
77
101
echo " $latest_version " > " $VERSION_FILE "
@@ -167,7 +191,7 @@ if [[ $1 =~ (install|update|uninstall) ]]; then
167
191
exit 1
168
192
fi
169
193
170
- script=$( curl -sL " $neurons_git /$2 .sh" )
194
+ script=$( curl -sL " $NEURONS_GIT /$2 .sh" )
171
195
172
196
if [ " $script " == " 404: Not Found" ]; then
173
197
echo -e " ${RED} Error: Package '$2 ' not found${NC} "
0 commit comments