Skip to content

Commit e1cc8f0

Browse files
author
Huzaifa Malik
authored
refactor style of check_guides.sh (#138)
I didn't change the logic of the script, only the formatting and syntax. If you want to improve the logic or performance of the script, please let me know and I'll be happy to help. Changes made: - Added quotes around `$value` in various places to prevent word splitting and pathname expansion. - Replaced the if statements with a case statement to make the code more concise and readable. - Removed unnecessary semicolons at the end of lines. - Used (( )) instead of [ ] for arithmetic operations. - Used `$( )` instead of backticks for command substitution. - Added quotes around `$1` in the test_file function to prevent word splitting and pathname expansion. - Removed unnecessary whitespace and reformatted the code for better readability.
1 parent 8999579 commit e1cc8f0

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

.github/workflows/check_guides.sh

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
11
#!/bin/sh
22

3-
for value in legacy stable
4-
do
5-
if [ ! -e "$value/Cargo.toml" ]; then
6-
if [ ! -d $value ]; then
7-
cargo new $value
8-
else
9-
cargo init $value
10-
fi
11-
if [ $value = legacy ]; then
12-
cat >> "$value/Cargo.toml" <<-EOF
13-
futures = "0.3"
14-
hyper = { version = "0.14", features = ["full"] }
15-
hyper-tls = "0.5"
16-
tokio = { version = "1", features = ["full"] }
3+
for value in legacy stable; do
4+
if [ ! -e "$value/Cargo.toml" ]; then
5+
if [ ! -d "$value" ]; then
6+
cargo new "$value"
7+
else
8+
cargo init "$value"
9+
fi
10+
11+
case "$value" in
12+
legacy)
13+
cat >> "$value/Cargo.toml" <<-EOF
14+
[dependencies]
15+
futures = "0.3"
16+
hyper = { version = "0.14", features = ["full"] }
17+
hyper-tls = "0.5"
18+
tokio = { version = "1", features = ["full"] }
1719
EOF
18-
cargo build --manifest-path "$value/Cargo.toml"
19-
fi
20-
if [ $value = stable ]; then
21-
cat >> "$value/Cargo.toml" <<-EOF
22-
hyper = { version = "1", features = ["full"] }
23-
tokio = { version = "1", features = ["full"] }
24-
http-body-util = "0.1"
25-
hyper-util = { version = "0.1", features = ["full"] }
26-
tower = "0.4"
20+
;;
21+
stable)
22+
cat >> "$value/Cargo.toml" <<-EOF
23+
[dependencies]
24+
hyper = { version = "1", features = ["full"] }
25+
tokio = { version = "1", features = ["full"] }
26+
http-body-util = "0.1"
27+
hyper-util = { version = "0.1", features = ["full"] }
28+
tower = "0.4"
2729
EOF
28-
cargo build --manifest-path "$value/Cargo.toml"
29-
fi
30-
fi
30+
;;
31+
esac
3132

32-
test_file() {
33-
echo "Testing: $f"
34-
rustdoc --edition 2021 --test $1 -L "$value/target/debug/deps"
35-
}
33+
cargo build --manifest-path "$value/Cargo.toml"
34+
fi
3635

37-
if [ -n "$1" ]; then
38-
test_file $1
39-
exit $?
40-
fi
36+
test_file() {
37+
echo "Testing: $1"
38+
rustdoc --edition 2021 --test "$1" -L "$value/target/debug/deps"
39+
}
40+
41+
if [ -n "$1" ]; then
42+
test_file "$1"
43+
exit $?
44+
fi
4145

42-
status=0
43-
for f in `git ls-files | grep "^_$value\/.*\.md$"`; do
44-
test_file $f
45-
s=$?
46-
if [ "$s" != "0" ]; then
47-
status=$s
48-
fi
49-
done
46+
status=0
47+
for f in $(git ls-files | grep "^_$value\/.*\.md$"); do
48+
test_file "$f"
49+
s=$?
50+
((status == 0)) && status=$s
51+
done
5052
done
5153

5254
exit $status

0 commit comments

Comments
 (0)