Commit 13d062c 1 parent dd633a6 commit 13d062c Copy full SHA for 13d062c
File tree 8 files changed +178
-71
lines changed
8 files changed +178
-71
lines changed Original file line number Diff line number Diff line change
1
+ tests=(
2
+ ' . src/utils/log.zsh; LOG_NAMESPACE=test1; Log'
3
+ ' . src/utils/log.zsh; LOG_NAMESPACE=test1; Log hello'
4
+ )
5
+
6
+ results=(
7
+ ' [test1] ' # TODO: This should be empty
8
+ ' [test1] hello'
9
+ )
Original file line number Diff line number Diff line change
1
+ # TODO: use expect to simulate user input
2
+
3
+ # tests=(
4
+ # valid response
5
+ # '. src/utils/prompt.zsh; valid_opts=("y" "N"); echo y | Prompt "Are you sure?" "${valid_opts[@]}"'
6
+ # invalid response
7
+ # '. src/utils/prompt.zsh; valid_opts=("yeah" "nah"); echo nope | Prompt "You sure bruv" "${valid_opts[@]}"'
8
+ # )
9
+
10
+ # results=(
11
+ # '"y" "true"'
12
+ # '"nope" "false"'
13
+ # )
Original file line number Diff line number Diff line change @@ -13,16 +13,22 @@ package() {
13
13
. ${testFile}
14
14
15
15
testsCount=" ${# tests[@]} "
16
+ TEST_PASSED=true
16
17
17
18
for (( i = 0 ; i < ${testsCount} ; i++ )) ; do
18
- test_result=$( zsh -c " ${tests[$i]} " )
19
+ test_result=$( zsh -c " CONSOLE='/dev/null'; CLI_CONFIG_ROOT='$( pwd) '; ${tests[$i]} " )
20
+ echo
19
21
20
22
if [ " ${test_result} " != " ${results[$i]} " ]; then
21
- echo TEST FAILED: " zsh -c '${tests[$i]} '"
22
- echo " '${test_result} ' != '${results[$i]} '"
23
- echo
23
+ echo -n " 🙅♂️ "
24
+ TEST_PASSED=false
24
25
ANY_TESTS_FAILED=1
26
+ else
27
+ echo -n " ✅ "
25
28
fi
29
+
30
+ echo " $ zsh -c \" CLI_CONFIG_ROOT=$( pwd) ${tests[$i]} \" "
31
+ [ " ${VERBOSE} " = ' 1' ] && [ " ${TEST_PASSED} " == ' false' ] && echo " TEST FAILED: zsh -c '${tests[$i]} '" && echo " '${test_result} ' != '${results[$i]} '"
26
32
done
27
33
done
28
34
Original file line number Diff line number Diff line change 3
3
. ${CLI_CONFIG_ROOT} /src/utils/array.zsh
4
4
5
5
install () {
6
- # DEFAULT OPTIONS
7
- CCOPT_PROFILE=default
8
- CCOPT_NO_SUDO=' sudo'
9
- CCOPT_DEBIAN_FRONTEND=' '
10
- CCOPT_TOOLS=(' antigen' ' ohmyposh' ' nvm' ' pyenv' ' dotnet' ' tfenv' ' gvm' )
11
-
12
- # READ OPTIONS
13
- # Todo: Move to separate file
14
- while [[ $# -gt 0 ]]; do
15
- case $1 in
16
- -h | --help)
17
- . $CLI_CONFIG_ROOT /src/defs/usage.zsh
18
- usage
19
- exit
20
- ;;
21
- -c | --clean)
22
- CCOPT_CLEAN=true
23
- shift
24
- ;;
25
- -p | --profile)
26
- profiles=($( ls -1 $CLI_CONFIG_ROOT /profiles) )
27
- CCOPT_PROFILE=$2
28
- if [ " $( array_contains " $CCOPT_PROFILE " " ${profiles[@]} " ) " = " false" ]; then
29
- echo " The specified profile '$CCOPT_PROFILE ' does not exist. "
30
- echo " Available profiles: $( array_str ' | ' ${profiles[@]} ) "
31
- exit
32
- fi
33
- shift
34
- shift
35
- ;;
36
- -n | --no-sudo)
37
- CCOPT_NO_SUDO=' '
38
- shift
39
- ;;
40
- -t | --tools)
41
- allowedPrograms=($( ls -1 $CLI_CONFIG_ROOT /src/installers | sed ' s/\..*$//g' | sort | uniq) )
42
-
43
- if [ " $2 " = " " ]; then
44
- Log " \" -t|--tools\" No tool selected, skipping installation."
45
- exit
46
- fi
47
-
48
- CCOPT_TOOLS=($( echo $2 | sed ' s/,/\n/g' ) )
49
- invalidPrograms=()
50
- for program in " ${CCOPT_TOOLS[@]} " ; do
51
- (! test -f $CLI_CONFIG_ROOT /src/installers/${program} .install.zsh) && invalidPrograms+=($program )
52
- done
53
-
54
- if [ " ${# invalidPrograms[@]} " -ne 0 ]; then
55
- Log " \" -t|--tools\" Found invalid tools, skipping installation - '$( array_str ' ,' ${invalidPrograms[@]} ) '"
56
- exit
57
- fi
58
- shift
59
- shift
60
- ;;
61
- --ci)
62
- CCOPT_DEBIAN_FRONTEND=' DEBIAN_FRONTEND=noninteractive'
63
- shift
64
- ;;
65
- * )
66
- # Unrecognized option
67
- shift
68
- ;;
69
- esac
70
- done
71
-
72
6
# START INSTALL
73
7
Log " Starting install..."
74
8
Original file line number Diff line number Diff line change 3
3
. $CLI_CONFIG_ROOT /src/defs/usage.zsh
4
4
. $CLI_CONFIG_ROOT /src/utils/log.zsh
5
5
. $CLI_CONFIG_ROOT /src/defs/prereqs.zsh
6
+ . $CLI_CONFIG_ROOT /src/utils/read-options.zsh
6
7
7
8
main () {
8
9
mode=$1
9
10
10
11
prereqs " $@ "
11
12
12
13
# check if mode is valid
13
- modes=(' install' ' configure' )
14
+ modes=(' install' ' configure' ' uninstall ' )
14
15
IS_MODE_VALID=' false'
15
16
for i in ${modes[@]} ; do
16
17
if [ " ${i} " = " ${mode} " ]; then
@@ -31,6 +32,7 @@ main() {
31
32
32
33
. $CLI_CONFIG_ROOT /src/defs/${mode} .zsh
33
34
35
+ read_options " $@ "
34
36
$mode " $@ "
35
37
fi
36
38
}
Original file line number Diff line number Diff line change
1
+ . ${CLI_CONFIG_ROOT} /src/utils/array.zsh
2
+ . ${CLI_CONFIG_ROOT} /src/utils/log.zsh
3
+ . ${CLI_CONFIG_ROOT} /src/utils/prompt.zsh
4
+
5
+ uninstall () {
6
+ responseYesToAll=false
7
+ confirmationOptions=(' y' ' N' ' a' )
8
+
9
+ for tool in " ${CCOPT_TOOLS[@]} " ; do
10
+ if [ " ${responseYesToAll} " = " false" ]; then
11
+ while true ; do
12
+ response=($( echo $( Prompt " Are you sure you want to uninstall '${tool} '?" true " ${confirmationOptions[@]} " ) ) )
13
+ receivedValidResponse=" ${response[2]} "
14
+
15
+ enteredOption=$( echo " ${response[1]} " | tr ' A-Z' ' a-z' )
16
+
17
+ if [ " ${enteredOption} " = " a" ]; then
18
+ responseYesToAll=true
19
+ break
20
+ elif [ " ${enteredOption} " = " " ] || [ " ${receivedValidResponse} " = " true" ]; then
21
+ break
22
+ fi
23
+ done
24
+ else
25
+ enteredOption=" a"
26
+ fi
27
+
28
+ if [ " ${enteredOption} " = " " ] || [ " ${enteredOption} " = " n" ]; then
29
+ Log " Skipping uninstall of ${tool} ."
30
+ continue
31
+ fi
32
+
33
+ if [ " ${enteredOption} " = " y" ] || [ " ${enteredOption} " = " a" ]; then
34
+ Log " Running uninstall script for '${tool} '..."
35
+ uninstallScriptPath=" ${CLI_CONFIG_ROOT} /src/installers/${tool} .uninstall.zsh"
36
+ if [ -f " ${uninstallScriptPath} " ]; then
37
+ . ${uninstallScriptPath}
38
+ else
39
+ rm -rf ${CLI_CONFIG_ROOT} /current/${tool} 2> /dev/null
40
+ rm -rf ${CLI_CONFIG_ROOT} /current/conf/${tool} .conf.sh
41
+ fi
42
+ Log " Done."
43
+ fi
44
+ done
45
+ }
Original file line number Diff line number Diff line change
1
+ . ${CLI_CONFIG_ROOT} /src/utils/array.zsh
2
+
3
+ Prompt () {
4
+ if [ " ${CONSOLE} " = ' ' ]; then
5
+ console=' /dev/tty'
6
+ else
7
+ console=" ${CONSOLE} "
8
+ fi
9
+
10
+ message=$1
11
+ shift
12
+ caseInsensitive=$1
13
+ shift
14
+ valid_opts=(" $@ " )
15
+
16
+ valid_opts_str=$( array_str " /" " ${valid_opts[@]} " )
17
+ echo -n " ${message} (${valid_opts_str} ) " > $console
18
+ read response
19
+
20
+ if [ " ${caseInsensitive} " = " true" ]; then
21
+ valid_opts_lowered=()
22
+ for opt in " ${valid_opts[@]} " ; do valid_opts_lowered+=($( echo " ${opt} " | tr ' A-Z' ' a-z' ) ); done
23
+ responseLowered=$( echo " ${response} " | tr ' A-Z' ' a-z' )
24
+ isValid=$( array_contains " ${responseLowered} " " ${valid_opts_lowered[@]} " )
25
+ else
26
+ isValid=$( array_contains " ${response} " " ${valid_opts[@]} " )
27
+ fi
28
+
29
+ response=" ${response} \0 ${isValid} "
30
+ echo " ${response} "
31
+ }
Original file line number Diff line number Diff line change
1
+ read_options () {
2
+ # DEFAULT OPTIONS
3
+ CCOPT_PROFILE=default
4
+ CCOPT_NO_SUDO=' sudo'
5
+ CCOPT_DEBIAN_FRONTEND=' '
6
+ CCOPT_TOOLS=(' antigen' ' ohmyposh' ' nvm' ' pyenv' ' dotnet' ' tfenv' ' gvm' )
7
+
8
+ # READ OPTIONS
9
+ # Todo: Move to separate file
10
+ while [[ $# -gt 0 ]]; do
11
+ case $1 in
12
+ -h | --help)
13
+ . $CLI_CONFIG_ROOT /src/defs/usage.zsh
14
+ usage
15
+ exit
16
+ ;;
17
+ -c | --clean)
18
+ CCOPT_CLEAN=true
19
+ shift
20
+ ;;
21
+ -p | --profile)
22
+ profiles=($( ls -1 $CLI_CONFIG_ROOT /profiles) )
23
+ CCOPT_PROFILE=$2
24
+ if [ " $( array_contains " $CCOPT_PROFILE " " ${profiles[@]} " ) " = " false" ]; then
25
+ echo " The specified profile '$CCOPT_PROFILE ' does not exist. "
26
+ echo " Available profiles: $( array_str ' | ' ${profiles[@]} ) "
27
+ exit
28
+ fi
29
+ shift
30
+ shift
31
+ ;;
32
+ -n | --no-sudo)
33
+ CCOPT_NO_SUDO=' '
34
+ shift
35
+ ;;
36
+ -t | --tools)
37
+ allowedPrograms=($( ls -1 $CLI_CONFIG_ROOT /src/installers | sed ' s/\..*$//g' | sort | uniq) )
38
+
39
+ if [ " $2 " = " " ]; then
40
+ Log " \" -t|--tools\" No tool selected, skipping installation."
41
+ exit
42
+ fi
43
+
44
+ CCOPT_TOOLS=($( echo $2 | sed ' s/,/\n/g' ) )
45
+ invalidPrograms=()
46
+ for program in " ${CCOPT_TOOLS[@]} " ; do
47
+ (! test -f $CLI_CONFIG_ROOT /src/installers/${program} .install.zsh) && invalidPrograms+=($program )
48
+ done
49
+
50
+ if [ " ${# invalidPrograms[@]} " -ne 0 ]; then
51
+ Log " \" -t|--tools\" Found invalid tools, skipping installation - '$( array_str ' ,' ${invalidPrograms[@]} ) '"
52
+ exit
53
+ fi
54
+ shift
55
+ shift
56
+ ;;
57
+ --ci)
58
+ CCOPT_DEBIAN_FRONTEND=' DEBIAN_FRONTEND=noninteractive'
59
+ shift
60
+ ;;
61
+ * )
62
+ # Unrecognized option
63
+ shift
64
+ ;;
65
+ esac
66
+ done
67
+ }
You can’t perform that action at this time.
0 commit comments