Skip to content

Commit

Permalink
Abort if invalid command-line option is given
Browse files Browse the repository at this point in the history
  • Loading branch information
terminationshock committed Nov 5, 2023
1 parent 47da6b8 commit 75527e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 6 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 75527e5

Please sign in to comment.