On Wed, Nov 9, 2022 at 12:09 PM Thomas Monjalon <thomas@monjalon.net> wrote:
The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check.
In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/dts-check-format.sh | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/devtools/dts-check-format.sh b/devtools/dts-check-format.sh
index dc07150775..eb1bdd2a01 100755
--- a/devtools/dts-check-format.sh
+++ b/devtools/dts-check-format.sh
@@ -3,11 +3,10 @@
 # Copyright(c) 2022 University of New Hampshire

 usage() {
-       echo "Run formatting and linting programs for DTS. Usage:"
-
+       echo 'Usage: $(basename $0) [options] [directory]'
+       echo 'Options:'
        # Get source code comments after getopts arguments and print them both
        grep -E '[a-zA-Z]+\) +#' "$0" | tr -d '#'
-       exit 0
 }

 format=true
@@ -17,7 +16,9 @@ lint=true
 while getopts "hfl" arg; do
        case $arg in
        h) # Display this message
+               echo 'Run formatting and linting programs for DTS.'
                usage
+               exit 0
                ;;
        f) # Don't run formatters
                format=false
@@ -25,10 +26,15 @@ while getopts "hfl" arg; do
        l) # Don't run linter
                lint=false
                ;;
-       *)
+       ?)
+               usage
+               exit 1
        esac
 done
+shift $(($OPTIND - 1))

+directory=${1:-$(dirname $0)/../dts}
+cd $directory || exit 1

 errors=0

--
2.36.1


Looks good to me.

Reviewed-by: Owen Hilyard <ohilyard@iol.unh.edu