Skip to content

Commit 112e61c

Browse files
committed
feat: add regex match
1 parent 21182e1 commit 112e61c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

ros2_ws_same_versions_lint

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ set -e
88
# Example:
99
# ./ros2_ws_same_versions_lint --src="./workspace/src"
1010
help() {
11-
usage="$(basename "$0") --src=<SRC> [ --help ]
11+
usage="$(basename "$0") --src=<SRC> [--regex=<REGEX>] [ --help ]
1212
1313
Check all ROS packages in the workspace have the same version
1414
1515
Arguments:
1616
--help Show this help text
1717
--src Source folder of all ros packages (mandatory)
18+
--regex Package name need to match a regex (optional, Default=\".*\")
1819
"
1920
echo "${usage}"
2021
}
@@ -26,6 +27,10 @@ case $i in
2627
SRC="${i#*=}"
2728
shift # past argument=value
2829
;;
30+
--regex=*)
31+
REGEX="${i#*=}"
32+
shift # past argument=value
33+
;;
2934
--help)
3035
HELP=YES
3136
shift # past argument with no value
@@ -47,6 +52,10 @@ if [ -z "${SRC}" ]; then
4752
exit 1
4853
fi
4954

55+
if [ -z "${REGEX}" ]; then
56+
REGEX=".*"
57+
fi
58+
5059
# Will throw an error if not installed
5160
if ! command -v xmllint &> /dev/null
5261
then
@@ -56,8 +65,7 @@ fi
5665

5766
# Checking package.xml
5867

59-
result=$(find "${SRC}" -name package.xml -exec xmllint --xpath 'package/version/text()' {} \; | tr '\n' ' ')
60-
68+
result=$(find "${SRC}" -maxdepth 2 -regextype egrep -regex ".*${REGEX}/package.xml" -exec xmllint --xpath 'package/version/text()' {} \; | tr '\n' ' ')
6169
array=()
6270
IFS=', ' read -r -a array <<< "${result}"
6371

0 commit comments

Comments
 (0)