util/lint/lint: Add command line parsing
The lint script just did very basic argument parsing and required the sub-command and --junit argument to be in specific locations. I'm adding additional commands, so the first step is to add true command line parsing. Signed-off-by: Martin Roth <gaumless@gmail.com> Change-Id: I7118c29e6c5d785b35a7ae12cf5984c43ebc3ab9 Reviewed-on: https://review.coreboot.org/c/coreboot/+/67191 Reviewed-by: Raul Rangel <rrangel@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
39914a50ae
commit
8ea8d856f3
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#set -x # uncomment for debug
|
#set -x # uncomment for debug
|
||||||
|
|
||||||
|
JUNIT=0
|
||||||
|
|
||||||
usage () {
|
usage () {
|
||||||
printf "Usage: %s <lint|lint-stable|lint-extended> [--junit]\n" "$0"
|
printf "Usage: %s <lint|lint-stable|lint-extended> [--junit]\n" "$0"
|
||||||
}
|
}
|
||||||
|
@ -16,9 +18,36 @@ junit_write () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ! cmd_args="$(getopt -l help,junit -o hJ -- "$@")"; then
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
eval set -- "${cmd_args}"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h | --help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-J | --junit)
|
||||||
|
echo "selected junit"
|
||||||
|
JUNIT=1
|
||||||
|
;;
|
||||||
|
--) shift; break ;;
|
||||||
|
*) break ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
#verify the first command line parameter
|
#verify the first command line parameter
|
||||||
if [ -z "$1" ] || [ "$1" != "lint" ] && [ "$1" != "lint-stable" ] && \
|
if [ -z "$1" ]; then
|
||||||
|
echo "Error: A sub-command is needed."
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
elif [ "$1" != "lint" ] && [ "$1" != "lint-stable" ] &&
|
||||||
[ "$1" != "lint-extended" ]; then
|
[ "$1" != "lint-extended" ]; then
|
||||||
|
echo "Error: $1 is not a valid sub-command."
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -30,13 +59,9 @@ if [ "$1" = "lint-extended" ]; then
|
||||||
fi
|
fi
|
||||||
FAILED=0;
|
FAILED=0;
|
||||||
|
|
||||||
#check optional second command line parameter.
|
if [ "${JUNIT}" -eq 1 ]; then
|
||||||
if [ "$2" = "--junit" ]; then
|
|
||||||
JUNIT=1
|
|
||||||
echo '<?xml version="1.0" encoding="utf-8"?>' > "$XMLFILE"
|
echo '<?xml version="1.0" encoding="utf-8"?>' > "$XMLFILE"
|
||||||
junit_write '<testsuite>'
|
junit_write '<testsuite>'
|
||||||
else
|
|
||||||
JUNIT=0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#run all scripts of the requested type
|
#run all scripts of the requested type
|
||||||
|
|
Loading…
Reference in New Issue