-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_diff.sh
executable file
·45 lines (39 loc) · 1.35 KB
/
generate_diff.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
#!/bin/bash
# Check if sed is available
if ! which sed > /dev/null; then
echo "sed could not be found"
exit 1
fi
# Check if cargo-expand is available
if ! cargo expand --version > /dev/null; then
echo "cargo-expand could not be found"
exit 1
fi
# wrapper around sed to account for mac/bsd/linux differences
sed_() {
# sed --version doesn't exist on macos
if ! sed --version > /dev/null 2>&1; then
args=( "$@" )
set --
for arg in "${args[@]}"; do
if [ "$arg" = "-i" ]; then
set -- "$@" "$arg" ""
else
set -- "$@" "$arg"
fi
done
fi
$(which sed) "$@"
}
sed_ -i 's/^#[[:space:]]serde_derive/serde_derive/g' Cargo.toml
sed_ -i 's/serde_versioning::Deserialize/serde_derive::Deserialize/g' examples/usage.rs
sed_ -i 's/#\[versioning/\/\/#\[versioning/g' examples/usage.rs
cargo expand --example usage > usage.expanded.initial.rs
sed_ -i 's/serde_derive::Deserialize/serde_versioning::Deserialize/g' examples/usage.rs
sed_ -i 's/\/\/#\[versioning/#\[versioning/g' examples/usage.rs
cargo expand --example usage > usage.expanded.modified.rs
diff -u usage.expanded.initial.rs usage.expanded.modified.rs > usage.diff
sed_ -i 's/^serde_derive[[:space:]]/# serde_derive /g' Cargo.toml
# clean-up
rm usage.expanded.initial.rs usage.expanded.modified.rs
exit 0