--- a/Smalltalk.st Wed Nov 02 18:04:46 2016 +0100
+++ b/Smalltalk.st Wed Nov 02 18:35:11 2016 +0100
@@ -4306,19 +4306,15 @@
Initializing := true.
keepSplashWindow := StartupClass perform:#keepSplashWindowOpen ifNotUnderstood:[false].
-"/ now done AFTER reading smalltalk.rc
-"/ keepSplashWindow ifFalse:[
-"/ self hideSplashWindow. "/ if there is one, it's now time to hide it
-"/ ].
"
while reading patches- and rc-file, do not add things into change-file
"
Class withoutUpdatingChangesDo:[
|commandFiles rcFile defaultRC prevCatchSetting
- isEval isPrint isFilter isRepl idxFileArg process|
-
- isEval := isPrint := isFilter := isRepl := false.
+ isEval isPrint isFilter isRepl isRunMain idxFileArg process|
+
+ isEval := isPrint := isFilter := isRepl := isRunMain := false.
didReadRCFile := false.
StandAlone ifFalse:[
@@ -4365,7 +4361,7 @@
].
].
- "/ look for a '-e filename' or '--execute filename' argument
+ "/ look for a '-e filename' or '--execute filename' or '--script filename' argument
"/ this will force fileIn of filename only, no standard startup.
idx := CommandLineArguments indexOfAny:#('-e' '--execute' '--script').
@@ -4424,7 +4420,7 @@
].
"look for a '-f filename' or '--file filename' argument
- if scripting, this is loaded before -P, -E or -R action.
+ if scripting, these are loaded before -P, -E or -R action.
if not scripting, this will force evaluation of filename instead of smalltalk.rc"
[
idxFileArg := CommandLineArguments indexOfAny:#('-f' '--file').
@@ -4446,16 +4442,18 @@
idx := CommandLineArguments indexOfAny:#('-F' '--filter').
(isFilter := (idx ~~ 0)) ifFalse:[
idx := CommandLineArguments indexOfAny:#('-R' '--repl').
- isRepl := (idx ~~ 0)
+ (isRepl := (idx ~~ 0)) ifFalse:[
+ idx := CommandLineArguments indexOf:#('--run').
+ isRunMain := (idx ~~ 0)
+ ].
].
].
].
- (isEval | isPrint | isFilter | isRepl) ifTrue:[
+ (isEval | isPrint | isFilter | isRepl | isRunMain) ifTrue:[
isRepl ifFalse:[
CommandLineArguments size <= idx ifTrue:[
- 'stx: missing argument after -E/-P/-F' errorPrintCR.
- self exit:1.
+ self exitWithErrorMessage:'missing argument after -E/-P/-F/--run.'.
].
arg := CommandLineArguments at:idx + 1.
CommandLineArguments removeAtIndex:idx+1.
@@ -4482,8 +4480,7 @@
('Smalltalk [info]: reading command file from: "', commandFile, '".') infoPrintCR.
].
(self secureFileIn:commandFile) ifFalse:[
- ('Smalltalk [error]: "', commandFile, '" not found.') errorPrintCR.
- OperatingSystem exit:1.
+ self exitWithErrorMessage:('"', commandFile, '" not found.').
]
]
].
@@ -4521,16 +4518,41 @@
line doIt:line.
].
] ifFalse:[
- "/ --print or --eval
- |rslt|
-
- rslt := Parser new
- evaluate:arg
- notifying:(EvalScriptingErrorHandler new source:arg)
- compile:true.
- isPrint ifTrue:[
- rslt printCR.
- ].
+ (isPrint | isEval) ifTrue:[
+ "/ --print or --eval
+ |rslt|
+
+ rslt := Parser new
+ evaluate:arg
+ notifying:(EvalScriptingErrorHandler new source:arg)
+ compile:true.
+ isPrint ifTrue:[
+ rslt printCR.
+ ].
+ ] ifFalse:[
+ "/ --run <className>
+ |className class|
+
+ className := arg.
+ class := Smalltalk classNamed:className.
+ class isNil ifTrue:[
+ self exitWithErrorMessage:'no such class: "', className, '".'
+ ].
+ class := class theMetaclass.
+ (class implements:#main:) ifTrue:[
+ class main:CommandLineArguments.
+ ] ifFalse:[
+ (class implements:#main) ifTrue:[
+ class main.
+ ] ifFalse:[
+ (class implements:#start) ifTrue:[
+ class start.
+ ] ifFalse:[
+ self exitWithErrorMessage:'class has no "main:", "main" or "start" method.'
+ ].
+ ].
+ ].
+ ].
].
].
@@ -4569,8 +4591,7 @@
[
commandFiles do:[:commandFile |
(self secureFileIn:commandFile) ifFalse:[
- ('Smalltalk [error]: startup file "', commandFile, '" not found.') errorPrintCR.
- OperatingSystem exit:1.
+ self exitWithErrorMessage:('startup file "', commandFile, '" not found.').
].
].
].
@@ -4830,6 +4851,11 @@
"
self exitOrError:0
"
+!
+
+exitWithErrorMessage:msg
+ ('Smalltalk [error]: ',msg) errorPrintCR.
+ self exitOrError:1
! !
!Smalltalk class methodsFor:'startup queries'!