8000 fix(stm32CubeProg): use BSD getopt for MacOS · stm32duino/Arduino_Tools@8fee15e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fee15e

Browse files
committed
fix(stm32CubeProg): use BSD getopt for MacOS
On MacOS getopt is the BSD based one while other using the gnu-based getopt. Then "-o" and long options are not supported Fixes #99 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 354699b commit 8fee15e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

stm32CubeProg.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -o nounset # Treat unset variables as an error
33
# set -o xtrace # Print command traces before executing command.
44

5+
UNAME_OS="$(uname -s)"
56
STM32CP_CLI=
67
INTERFACE=
78
PORT=
@@ -55,11 +56,21 @@ aborting() {
5556

5657
# parse command line arguments
5758
# options may be followed by one colon to indicate they have a required arg
58-
if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
59-
echo "Terminating..." >&2
60-
exit 1
61-
fi
62-
59+
case "${UNAME_OS}" in
60+
Darwin*)
61+
echo "Warning: long options not supported due to getopt from FreeBSD usage."
62+
if ! options=$(getopt hi:ef:o:c:r:d:v:p: "$@"< E351 /span>); then
63+
echo "Terminating..." >&2
64+
exit 1
65+
fi
66+
;;
67+
*)
68+
if ! options=$(getopt -a -o hi:ef:o:c:r:d:v:p: --long help,interface:,erase,file:,offset:,com:,rts:,dtr:,vid:,pid: -- "$@"); then
69+
echo "Terminating..." >&2
70+
exit 1
71+
fi
72+
;;
73+
esac
6374
eval set -- "$options"
6475

6576
while true; do
@@ -109,10 +120,13 @@ while true; do
109120
shift
110121
break
111122
;;
123+
*)
124+
echo "Unknown option $1"
125+
usage 1
126+
;;
112127
esac
113128
done
114-
# Check STM32CubeProgrammer cli availability, fallback to dfu-util if protocol dfu
115-
UNAME_OS="$(uname -s)"
129+
# Check STM32CubeProgrammer cli availability
116130
case "${UNAME_OS}" in
117131
Linux*)
118132
STM32CP_CLI=STM32_Programmer.sh

0 commit comments

Comments
 (0)
0