-
Notifications
You must be signed in to change notification settings - Fork 0
/
callable.sh
110 lines (96 loc) · 3.25 KB
/
callable.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
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
#!/bin/bash
Apm_MODULES_FILE_NAME="Ashmodules"
Apm_MODULES_CLONE_DIRECTORY=".ash_modules_tmp"
Apm_MODULES_FILE_PATH="$Ash__CALL_DIRECTORY/$Apm_MODULES_FILE_NAME"
Apm_LOCAL_MODULES_DIRECTORY_PATH="$Ash__CALL_DIRECTORY/$Ash__MODULES_FOLDERNAME"
Apm_LOCAL_MODULES_CLONE_PATH="$Ash__CALL_DIRECTORY/$Apm_MODULES_CLONE_DIRECTORY"
##################################################
# This function is an alias for `ash self:help`.
##################################################
Apm__callable_main() {
Apm__callable_help
}
##################################################
# Displays relavant information on how to use
# this module
##################################################
Apm__callable_help() {
more "$Ash__ACTIVE_MODULE_DIRECTORY/HELP.txt"
}
##################################################
# This function will initialize the current
# directory so it can start installing modules
##################################################
Apm__callable_init() {
# Hasn't been created
if [[ ! -f "$Apm_MODULES_FILE_PATH" ]]; then
touch "$Apm_MODULES_FILE_PATH"
Logger__success "Directory successfully initialized"
# Has already been created
else
Logger__error "Directory is already initialized"
fi
}
##################################################
# This function will install all of the modules
# from the Ashmodules file when passed no
# parameters.
#
# When this function is passed a parameter ($1),
# it will install a single module
#
# @param $1: The git HTTP or SSH URL to install
# @param $2: `--global` to install globally
##################################################
Apm__callable_install() {
# Creating modules directory
if [[ "$2" != "--global" && ! -d "$Apm_LOCAL_MODULES_DIRECTORY_PATH" ]]; then
mkdir "$Apm_LOCAL_MODULES_DIRECTORY_PATH"
touch "$Apm_LOCAL_MODULES_DIRECTORY_PATH/$Ash__MODULE_ALIASES_FILE"
fi
# If user is passing in URL
if [[ -n "$1" ]]; then
Apm_install_url "$@"
# User is not passing URL
else
Apm_install_modules_file
fi
}
##################################################
# This function will display a list of all of the
# global modules that are currently installed.
##################################################
Apm__callable_modules() {
local line=""
local global_aliases="$Ash__SOURCE_DIRECTORY/$Ash__GLOBAL_MODULES_DIRECTORY/$Ash__MODULE_ALIASES_FILE"
# Create global aliases if it doesn't exist
if [[ ! -f "$global_aliases" ]]; then
touch "$global_aliases"
fi
while read line; do
echo "${line//:/ =>}"
done < "$global_aliases"
}
##################################################
# This function will update a global module or
# Ash itself.
#
# @param $1: The alias or package of a global
# module. To update Ash itself, simply just pass
# `ash` here.
##################################################
Apm__callable_update(){
local module_name="$1"
# Checking if we're passing a module name
if [[ -z "$module_name" ]]; then
Logger__error "Requires a valid module name (or \"ash\") to be passed in"
return
fi
# Update
if [[ "$module_name" = 'ash' ]]; then
Apm_update_ash
return
else
Apm_update_module "$module_name"
fi
}