Skip to content

Commit d713412

Browse files
scala binary can execute scripts
1 parent 8c41a29 commit d713412

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

dist/bin/scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ source "$PROG_HOME/bin/common"
4040
declare -a residual_args
4141
execute_repl=false
4242
execute_run=false
43+
execute_script=false
4344
with_compiler=false
4445
class_path_count=0
46+
is_at_first_residual_argument=true
4547
CLASS_PATH=""
4648

4749
# Little hack to check if all arguments are options
@@ -79,17 +81,27 @@ while [[ $# -gt 0 ]]; do
7981
addDotcOptions "${1}"
8082
shift ;;
8183
*)
84+
if [ $is_at_first_residual_argument == true ] && [[ "$1" == *.scala ]]; then
85+
execute_script=true
86+
target_script="$1"
87+
fi
88+
is_at_first_residual_argument=false
8289
residual_args+=("$1")
8390
shift
8491
;;
8592

8693
esac
8794
done
88-
if [ $execute_repl == true ] || ([ $execute_run == false ] && [ $options_indicator == 0 ]); then
95+
96+
if [ $execute_repl == true ] || [ $execute_script == true ] || ([ $execute_run == false ] && [ $options_indicator == 0 ]); then
8997
if [ "$CLASS_PATH" ]; then
9098
cp_arg="-classpath \"$CLASS_PATH\""
9199
fi
92-
echo "Starting scala3 REPL..."
100+
if [ $execute_script == true ]; then
101+
echo "Running script $target_script"
102+
else
103+
echo "Starting scala3 REPL..."
104+
fi
93105
eval "\"$PROG_HOME/bin/scalac\" $cp_arg ${java_options[@]} -repl ${residual_args[@]}"
94106
elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then
95107
cp_arg="$DOTTY_LIB$PSEP$SCALA_LIB"

0 commit comments

Comments
 (0)