# HG changeset patch # User Claus Gittinger # Date 1475680525 -7200 # Node ID 1bd3cf6ce3305258d8d9d6284edc39774ff76809 # Parent aa136f213ebb6fe2243f2dbe88c171bf71e9e22f #FEATURE by cg class: SmalltalkCodeGeneratorTool added: #codeFor_standAloneMainOnClassSide changed: #codeFor_standAloneMain #codeFor_standAloneUsage better templates diff -r aa136f213ebb -r 1bd3cf6ce330 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: + -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 ............ a-argument(s)''. + Stderr nextPutLine:'' -b ............ b-argument(s)''. + Stderr nextPutLine:'' -c ................... c-option''. '. "Created: / 19-08-2011 / 02:22:46 / cg"