From 75527e541460f04651f212570ec7902446923ebf Mon Sep 17 00:00:00 2001 From: Tobias Melson Date: Sun, 5 Nov 2023 18:39:16 +0100 Subject: [PATCH] Abort if invalid command-line option is given --- src/config.go | 4 ++++ test.sh | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config.go b/src/config.go index ad922ad..fe34dc1 100644 --- a/src/config.go +++ b/src/config.go @@ -77,6 +77,10 @@ func NewConfig() *Config { return err == nil && stat.IsDir() } default: + if strings.HasPrefix(arg, "--") { + fmt.Fprintln(os.Stderr, "Invalid command-line option " + arg) + os.Exit(1) + } remainingArgs = append(remainingArgs, arg) } } diff --git a/test.sh b/test.sh index 98ddece..279fa13 100755 --- a/test.sh +++ b/test.sh @@ -164,12 +164,17 @@ function run() { echo -e "[::r]3.14[::-]\n[::r]70.1[::-]\n[::r]200[::-]" > test/EXPECT_$1 diff test/RESULT_$1 test/EXPECT_$1 ;; + 32) + echo -e "foobar\n" | ./lisst --foobar 2> test/RESULT_$1 + echo "Invalid command-line option --foobar" > test/EXPECT_$1 + diff test/RESULT_$1 test/EXPECT_$1 + ;; esac } if [ $# -eq 0 ]; then result=0 - for i in {1..31}; do + for i in {1..32}; do echo "Test $i" run $i || { result=1; echo " FAILED"; } done