#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 05 Oct 2016 17:15:25 +0200
changeset 16900 1bd3cf6ce330
parent 16899 aa136f213ebb
child 16901 0023fed870de
#FEATURE by cg class: SmalltalkCodeGeneratorTool added: #codeFor_standAloneMainOnClassSide changed: #codeFor_standAloneMain #codeFor_standAloneUsage better templates
SmalltalkCodeGeneratorTool.st
--- a/SmalltalkCodeGeneratorTool.st	Wed Oct 05 17:03:56 2016 +0200
+++ b/SmalltalkCodeGeneratorTool.st	Wed Oct 05 17:15:25 2016 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2002 by eXept Software AG
               All Rights Reserved
@@ -2576,44 +2574,96 @@
 codeFor_standAloneMain
     ^
 'main:argv
-    "main entry; argv is the array of command arguments (as array of words from space-separated command line).
+',
+(generateComments 
+    ifTrue:[
+'    "main entry; argv is the array of command arguments 
+     (as array of words from space-separated command line).
      Parse arguments, and proceed to the real work function"
 
-    "you may want to put those into instvars, in order to be accessible from the doRealWork function"
-    |aArgs bArgs cOption fileArgs helpOption|
+    "you may want to put those into instvars, in order to be accessible from the realMain: function"
+'] 
+    ifFalse:['']
+),
+'    |aArgs bArgs cOption fileArgs helpOption|
 
     aArgs := OrderedCollection new.
     bArgs := OrderedCollection new.
     fileArgs := OrderedCollection new.
     cOption := helpOption := false.
 
-    (GetOpt new)
+',
+(generateComments 
+    ifTrue:[
+'    "/ this is a template for getOpt usage:
+    "/ - will collect -a <...> arguments into aArgs,
+    "/ - will collect -b <...> arguments into bArgs,
+    "/ - will set cOption to true if there is a -c argument
+    "/ - will set helpOption to true if there is a -h argument
+    "/ - will show the usage and exit for a -? argument
+']    
+    ifFalse:['']
+),
+'    (GetOpt new)
 "/        at:$a
 "/            put:[:opt :arg | aArgs add:arg];
 "/        at:$b
 "/            put:[:opt :arg | bArgs add:arg];
-"/        at:$b
+"/        at:$c
 "/            put:[:opt | cOption := true];
         at:$h
             put:[:opt | helpOption := true];
         at:$?
-            put:[:arg | self usage. Smalltalk exitIfStandalone:0];
+            put:[:arg | self class usage. ^ Smalltalk exitIfStandalone:0];
         default:[:arg | fileArgs add:arg];
         onError:[:msg | Stderr nextPutLine:msg. self usage];
         parse:argv.
 
     helpOption ifTrue:[
-        self usage.
+        self class usage.
     ] ifFalse:[
         self realMain:argv.
     ].
-    "/ do not exit here; caller will go into event loop when returning
+',
+(generateComments 
+    ifTrue:[
+'    "/ (maybe) do not exit here; 
+    "/ caller will go into event loop when a display has been opened and we return here
+    "/ for real non-ui apps, exit with an exitcode of 0
+'] 
+    ifFalse:['']
+),
+'    ^ Smalltalk exitIfStandalone:0
 '.
 
     "Created: / 19-08-2011 / 02:18:49 / cg"
     "Modified: / 06-06-2016 / 14:58:15 / cg"
 !
 
+codeFor_standAloneMainOnClassSide
+    generateComments ifFalse:[
+        ^
+'main:argv
+    ^ self new main:argv
+'.
+    ].
+    
+    ^
+'main:argv
+    "main entry; argv is the array of command arguments 
+     (as array of words from space-separated command line).
+     Creates an instance of myself and calls the main: method on the instance side."
+
+    ^ self new main:argv
+    
+    "to try from within the IDE:
+        self main:#(''-a'' ''someArg'' ''-h'')
+     when deployed, start at the command line with:
+        <nameOfApp> -a someArg -h
+    "
+'.
+!
+
 codeFor_standAloneRealMainMethodFor:aClass
     |appClass|
 
@@ -2641,10 +2691,14 @@
 codeFor_standAloneUsage
     ^
 'usage
+    "output some command-line usage infos on stderr"
+    
     Stderr nextPutLine:''usage: '',self applicationName,'' [options...]''.
-    Stderr nextPutLine:''  -h .................. output this message''.
-
-    Smalltalk isStandAloneApp ifTrue:[ Smalltalk exitIfStandalone:1 ].
+    Stderr nextPutLine:''  --noInfoPrint ........ disable diagnostic messages''.
+    Stderr nextPutLine:''  -h ................... output this message''.
+    Stderr nextPutLine:''  -a <file> ............ a-argument(s)''.
+    Stderr nextPutLine:''  -b <file> ............ b-argument(s)''.
+    Stderr nextPutLine:''  -c ................... c-option''.
 '.
 
     "Created: / 19-08-2011 / 02:22:46 / cg"