mirror of https://github.com/CrimsonTome/tldr.git
check-pr: add < and > as special cases and refactor (#11841)
parent
7b6c610196
commit
4e280a9efe
|
@ -61,6 +61,31 @@ function check_missing_english_page() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function count_commands() {
|
||||||
|
local file="$1"
|
||||||
|
local regex="$2"
|
||||||
|
|
||||||
|
grep -c "$regex" "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
function strip_commands() {
|
||||||
|
local file="$1"
|
||||||
|
local regex="$2"
|
||||||
|
|
||||||
|
local stripped_commands=()
|
||||||
|
|
||||||
|
mapfile -t stripped_commands < <(
|
||||||
|
grep "$regex" "$file" |
|
||||||
|
sed 's/{{[^}]*}}/{{}}/g' |
|
||||||
|
sed 's/<[^>]*>//g' |
|
||||||
|
sed 's/"[^"]*"/""/g' |
|
||||||
|
sed "s/'[^']*'//g" |
|
||||||
|
sed 's/`//g'
|
||||||
|
)
|
||||||
|
|
||||||
|
printf "%s\n" "${stripped_commands[*]}"
|
||||||
|
}
|
||||||
|
|
||||||
function check_outdated_page() {
|
function check_outdated_page() {
|
||||||
local page=$1
|
local page=$1
|
||||||
local english_page="pages/${page#pages*\/}"
|
local english_page="pages/${page#pages*\/}"
|
||||||
|
@ -70,15 +95,17 @@ function check_outdated_page() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local english_commands=$(grep -c $command_regex "$english_page")
|
local english_commands
|
||||||
mapfile -t stripped_english_commands < <(grep $command_regex "$english_page" | sed 's/{{[^}]*}}/{{}}/g' | sed 's/"[^"]*"/""/g' | sed "s/'[^']*'//g" | sed 's/`//g')
|
english_commands=$(count_commands "$english_page" "$command_regex")
|
||||||
local commands=$(grep -c $command_regex $page)
|
local commands
|
||||||
mapfile -t stripped_commands < <(grep $command_regex "$page" | sed 's/{{[^}]*}}/{{}}/g' | sed 's/"[^"]*"/""/g' | sed "s/'[^']*'//g" | sed 's/`//g')
|
commands=$(count_commands "$page" "$command_regex")
|
||||||
|
|
||||||
local english_commands_as_string=$(printf "%s\n" "${stripped_english_commands[*]}")
|
local english_commands_as_string
|
||||||
local commands_as_string=$(printf "%s\n" "${stripped_commands[*]}")
|
english_commands_as_string=$(strip_commands "$english_page" "$command_regex")
|
||||||
|
local commands_as_string
|
||||||
|
commands_as_string=$(strip_commands "$page" "$command_regex")
|
||||||
|
|
||||||
if [[ $english_commands != $commands ]]; then
|
if [[ "$english_commands" != "$commands" ]]; then
|
||||||
printf "\x2d $MSG_OUTDATED" "$page" "based on number of commands"
|
printf "\x2d $MSG_OUTDATED" "$page" "based on number of commands"
|
||||||
elif [[ "$english_commands_as_string" != "$commands_as_string" ]]; then
|
elif [[ "$english_commands_as_string" != "$commands_as_string" ]]; then
|
||||||
printf "\x2d $MSG_OUTDATED" "$page" "based on the command contents itself"
|
printf "\x2d $MSG_OUTDATED" "$page" "based on the command contents itself"
|
||||||
|
|
Loading…
Reference in New Issue