File tree Expand file tree Collapse file tree 2 files changed +65
-7
lines changed
share/github-backup-utils Expand file tree Collapse file tree 2 files changed +65
-7
lines changed Original file line number Diff line number Diff line change 7
7
set -o pipefail
8
8
9
9
# set the variable from the first argument and remove any leading dashes
10
- rsync_command=$( echo " $1 " | sed -E ' s/^-+// ' )
10
+ rsync_command=$1
11
11
12
- # check if the passed rsync command is supported by the current version of rsync
13
- if rsync -h | grep -E " \B-+($rsync_command )\b" > /dev/null 2>&1 ; then
14
- echo " true"
12
+ # extract dashes if present into variable
13
+ leading_dashes=$( echo " $rsync_command " | grep -oE " ^-+" )
14
+
15
+ # this normalizes the passed command by removing any leading dashes
16
+ normalized_command=$( echo " $rsync_command " | sed -E " s/^-+//" )
17
+
18
+ # this checks the rsync command and returns the found command if it is valid
19
+ found_command=$( rsync -h | grep -oE " \B-+($normalized_command )\b" | head -n " 1" )
20
+
21
+ # this is the normalized found command
22
+ normalized_found_command=$( echo " $found_command " | sed -E " s/^-+//" )
23
+
24
+ # # Check if $leading_dashes is either - or --
25
+ if [ " $leading_dashes " == " -" ]; then
26
+ # check if the passed rsync command is valid and supported or if the normalized command is valid and supported
27
+ if [ " $rsync_command " == " $found_command " ]; then
28
+ echo " true"
29
+ else
30
+ echo " false"
31
+ fi
32
+ elif [ " $leading_dashes " == " --" ]; then
33
+ # check if the passed rsync command is valid and supported or if the normalized command is valid and supported
34
+ if [ " $rsync_command " == " $found_command " ]; then
35
+ echo " true"
36
+ else
37
+ echo " false"
38
+ fi
15
39
else
16
- echo " false"
17
- fi
40
+ # check if the passed rsync command is valid and supported or if the normalized command is valid and supported
41
+ if [ " $rsync_command " == " $normalized_found_command " ]; then
42
+ echo " true"
43
+ else
44
+ echo " false"
45
+ fi
46
+ fi
47
+
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ TESTS_DIR="$PWD/$(dirname "$0")"
8
8
9
9
# # testing for known supported command help with and without leading dashes
10
10
11
- begin_test " Testing ghe-rsync-feature-checker for known supported command --help"
11
+ begin_test " Testing ghe-rsync-feature-checker with known supported command --help"
12
12
(
13
13
set -e
14
14
@@ -17,6 +17,15 @@ begin_test "Testing ghe-rsync-feature-checker for known supported command --help
17
17
)
18
18
end_test
19
19
20
+ begin_test " Testing ghe-rsync-feature-checker with known unsupported command -help"
21
+ (
22
+ set -e
23
+
24
+ # Test ghe-rsync-feature-checker command
25
+ ghe-rsync-feature-checker -help | grep -q " false"
26
+ )
27
+ end_test
28
+
20
29
begin_test " Testing ghe-rsync-feature-checker with known supported command help"
21
30
(
22
31
set -e
@@ -38,6 +47,16 @@ begin_test "Testing ghe-rsync-feature-checker with known unsupported command --n
38
47
)
39
48
end_test
40
49
50
+ begin_test " Testing ghe-rsync-feature-checker with known unsupported command -not-an-actual-feature"
51
+ (
52
+ set -e
53
+
54
+ # Test ghe-rsync-feature-checker command
55
+ ghe-rsync-feature-checker -not-an-actual-feature | grep -q " false"
56
+
57
+ )
58
+ end_test
59
+
41
60
begin_test " Testing ghe-rsync-feature-checker with known unsupported command not-an-actual-feature"
42
61
(
43
62
set -e
@@ -98,6 +117,15 @@ begin_test "Testing ghe-rsync-feature-checker with known supported command --ver
98
117
)
99
118
end_test
100
119
120
+ begin_test " Testing ghe-rsync-feature-checker with known unsupported command -verbose"
121
+ (
122
+ set -e
123
+
124
+ # Test ghe-rsync-feature-checker command
125
+ ghe-rsync-feature-checker -verbose | grep -q " false"
126
+ )
127
+ end_test
128
+
101
129
begin_test " Testing ghe-rsync-feature-checker with known supported command verbose"
102
130
(
103
131
set -e
You can’t perform that action at this time.
0 commit comments