Revise cli.sh

This commit is contained in:
chonghe
2023-09-06 16:39:03 +08:00
parent 996571362b
commit a180809238
2 changed files with 13 additions and 13 deletions

View File

View File

@@ -37,10 +37,10 @@ bn_cli=$($CMD bn --help)
vc_cli=$($CMD vc --help) vc_cli=$($CMD vc --help)
am_cli=$($CMD am --help) am_cli=$($CMD am --help)
general=./general_help.md general=./help_general.md
bn=./bn_help.md bn=./help_bn.md
vc=./vc_help.md vc=./help_vc.md
am=./am_help.md am=./help_am.md
# create .md files # create .md files
write_to_file "$general_cli" "$general" "Lighthouse General Commands" write_to_file "$general_cli" "$general" "Lighthouse General Commands"
@@ -51,12 +51,12 @@ write_to_file "$am_cli" "$am" "Account Manager"
# create empty array to store variables for exit condition later # create empty array to store variables for exit condition later
exist=() exist=()
update=() update=()
for i in general_help bn_help vc_help am_help for i in help_general help_bn help_vc help_am
do do
if [[ -f ./book/src/cli/$i.md ]]; # first check if .md exists if [[ -f ./book/src/$i.md ]]; # first check if .md exists
then then
echo "$i.md exists, continue to check for any changes" echo "$i.md exists, continue to check for any changes"
difference=$(diff ./book/src/cli/$i.md $i.md) difference=$(diff ./book/src/$i.md $i.md)
case1=false case1=false
exist+=($case1) exist+=($case1)
if [[ -z $difference ]]; # then check if any changes required if [[ -z $difference ]]; # then check if any changes required
@@ -65,27 +65,27 @@ do
update+=($case2) update+=($case2)
echo "$i.md is up to date" echo "$i.md is up to date"
else else
cp $i.md ./book/src/cli/$i.md cp $i.md ./book/src/$i.md
echo "$i has been updated" echo "$i has been updated"
case2=true case2=true
update+=($case2) update+=($case2)
fi fi
else else
echo "$i.md is not found, it will be created now" echo "$i.md is not found, it will be created now"
cp $i.md ./book/src/cli/$i.md cp $i.md ./book/src/$i.md
case1=true case1=true
exist+=($case1) exist+=($case1)
fi fi
done done
# use during testing to show exit conditions # use during testing to show exit conditions
#echo "${exist[@]}" echo "${exist[@]}"
#echo "${update[@]}" echo "${update[@]}"
# exit condition, exit when .md does not exist or changes requried # exit condition, exit when .md does not exist or changes requried
if [[ ${exist[@]} == *"true"* && ${update[@]} == *"true"* ]]; if [[ ${exist[@]} == *"true"* && ${update[@]} == *"true"* ]];
then then
echo "exit 1 due to one or more .md file does not exist and changes updated" echo "exit 1 due to one or more .md file does not exist and changes updated."
exit 1 exit 1
elif [[ ${exist[@]} == *"true"* ]]; elif [[ ${exist[@]} == *"true"* ]];
then then
@@ -100,4 +100,4 @@ else
fi fi
# remove .md files in current directory # remove .md files in current directory
rm -f general_help.md bn_help.md vc_help.md am_help.md rm -f help_general.md help_bn.md help_vc.md help_am.md