Fix in argument parsing in HGInstaller.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 11 Jul 2013 01:50:39 +0100
changeset 332 fba502c3fe50
parent 331 379018400fc1
child 333 7ec547d30e86
Fix in argument parsing in HGInstaller. Argument parsing fixed and errors are properly reported using log:severity. Fixes issue #13.
mercurial/HGInstaller.st
--- a/mercurial/HGInstaller.st	Wed Jul 10 12:19:43 2013 +0100
+++ b/mercurial/HGInstaller.st	Thu Jul 11 01:50:39 2013 +0100
@@ -109,6 +109,17 @@
 
 !HGInstaller class methodsFor:'defaults'!
 
+allowCoverageMeasurementOption
+    "enable/disable the --measureCoverage startup options.
+     The default is false, so standAlone apps do not support coverage measurements by default.
+     Can be redefined in subclasses to enable it 
+     (but will need the libcomp and possibly the programming/oom packages to be present)"
+
+    ^ false
+
+    "Created: / 11-07-2013 / 01:37:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 allowDebugOption
     "enable/disable the --debug startup option.
      Can be redefined in subclasses to enable it"
@@ -175,6 +186,42 @@
 
     "Modified: / 07-07-2013 / 18:26:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified (format): / 07-07-2013 / 22:00:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+usage
+    Stderr nextPutLine:'stx:libscm installation script'; cr.
+    Stderr nextPutLine:'usage: stx --execute HGInstaller.st [options...]'.
+    Stderr nextPutLine:'  --version REV ........... specifies which version to install. REV can be'.
+    Stderr nextPutLine:'                            branch, tag or commit id.'.
+    Stderr nextPutLine:'  --archive FILE .......... specifies an archive file to install. If ommited'.
+    Stderr nextPutLine:'                            archive is donwloaded'.
+    Stderr nextPutLine:'  --help .................. output this message'.
+"/    Stderr nextPutLine:'  --verbose ............... verbose startup'.
+"/    Stderr nextPutLine:'  --noBanner .............. no splash screen'.
+"/    Stderr nextPutLine:'  --newAppInstance ........ start as its own application process (do not reuse a running instance)'.
+"/    self allowScriptingOption ifTrue:[
+"/        Stderr nextPutLine:'  --scripting portNr ...... enable scripting via port (or stdin/stdOut, if 0)'.
+"/    ].
+    self allowDebugOption ifTrue:[
+        Stderr nextPutLine:'  --debug ................. enable Debugger'.
+    ].
+    self allowCoverageMeasurementOption ifTrue:[
+        Stderr nextPutLine:'  --coverage .............. turn on coverage measurement'.
+        Stderr nextPutLine:'     [+/-]package: pattern ...  - include/exclude packages'.
+        Stderr nextPutLine:'     [+/-]class: pattern ...    - include/exclude classes'.
+        Stderr nextPutLine:'     [+/-]method: cls#sel ...   - include/exclude methods'.
+    ].
+    self suppressRCFileReading ifFalse:[
+        Stderr nextPutLine:'  --rcFileName file ....... execute code from file on startup (default: ',self startupFilename,')'.
+    ].
+    Stderr cr.
+    Stderr nextPutLine:'For more information see wiki:'.
+    Stderr nextPutLine:'  https://bitbucket.org/janvrany/stx-libscm/wiki/Installation'.
+    Stderr cr.
+
+    Smalltalk exit: 0
+
+    "Created: / 11-07-2013 / 01:36:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGInstaller class methodsFor:'startup-private'!
@@ -283,7 +330,7 @@
 doConfigure
     | top rcd |
 
-    Transcript nextPutAll: 'Configuring...'; cr.
+    Transcript nextPutLine: 'Configuring...'.
     top := (Smalltalk getPackageDirectoryForPackage: Object package) directory directory.
     rcd := top / 'stx'/ 'projects' / 'smalltalk' / 'rc.d'.
     rcd isDirectory ifTrue:[
@@ -296,10 +343,10 @@
         ].            
     ] ifFalse:[
         
-    ]
+    ].
 
     "Created: / 07-07-2013 / 11:19:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 09-07-2013 / 01:31:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-07-2013 / 01:41:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 doDownload
@@ -317,7 +364,7 @@
         | downloaded url|
 
         url := base / (version , '.zip').
-        Transcript nextPutAll: url asString; nextPutAll: '...'.
+        Transcript nextPutAll:'  '; nextPutAll: url asString; nextPutAll: '...'.
         downloaded := self doDownload: url.
         Transcript nextPutAll: (downloaded ifTrue:['OK'] ifFalse:['FAILED']); cr.
         downloaded                        
@@ -332,7 +379,7 @@
     "/    ]
 
     "Created: / 07-07-2013 / 11:19:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 09-07-2013 / 01:19:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-07-2013 / 01:40:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 doDownload: url
@@ -480,55 +527,57 @@
 
     | i |
 
-    (Smalltalk getPackageDirectoryForPackage: Object package) isNil ifTrue:[
-        | cmd root |
-        cmd := OperatingSystem pathOfSTXExecutable asFilename asAbsoluteFilename.
-        root := cmd directory directory directory directory.
-        root infoPrintCR.
-        (root / 'stx' / 'libbasic') isDirectory ifFalse:[
-            self error: 'Cannot determine package path'.
-        ].
-        Smalltalk packagePath: (Smalltalk packagePath copyWith: root pathName).
-    ].
-
-    i := 1.
-    [ i <= argv size ] whileTrue:[
-        | a |
-
-        a := argv at: i.
-        a = '--version' ifTrue:[
-            i = argv size ifTrue:[
-                self error: '--version requires an argument!!'
+    [
+        (Smalltalk getPackageDirectoryForPackage: Object package) isNil ifTrue:[
+            | cmd root |
+            cmd := OperatingSystem pathOfSTXExecutable asFilename asAbsoluteFilename.
+            root := cmd directory directory directory directory.
+            root infoPrintCR.
+            (root / 'stx' / 'libbasic') isDirectory ifFalse:[
+                self log: 'Cannot determine package path' severity: SeverityError.
             ].
-            version := argv at: i + 1.
-            i := i + 2.            
+            Smalltalk packagePath: (Smalltalk packagePath copyWith: root pathName).
         ].
-        a = '--archive' ifTrue:[
-            i = argv size ifTrue:[
-                self error: '--archive requires an argument!!'
-            ].
-            archive := (argv at: i + 1) asFilename.
-            archive exists ifFalse:[
-                self error: ('File %1 does not exist' bindWith: archive pathName).
-            ].
-            archive isReadable ifFalse:[
-                self error: ('File %1 does is not readable!!' bindWith: archive pathName).
-            ].
-            (ZipArchive isZipArchive: archive) ifFalse:[
-                self error: ('File %1 is not a .zip archive!!' bindWith: archive pathName).
-            ].
-            i := i + 2.            
-        ].        
-    ].
+
+        i := 1.
+        [ i <= argv size ] whileTrue:[
+            | a |
 
-    [
+            a := argv at: i.
+            a = '--version' ifTrue:[
+                i = argv size ifTrue:[
+                    self error: '--version requires an argument!!'
+                ].
+                version := argv at: i + 1.
+                i := i + 2.            
+            ] ifFalse:[
+            a = '--archive' ifTrue:[
+                i = argv size ifTrue:[
+                    self log: '--archive requires an argument!!' severity: SeverityError
+                ].
+                archive := (argv at: i + 1) asFilename.
+                archive exists ifFalse:[
+                    self log: ('Archive %1 does not exist' bindWith: archive pathName) severity: SeverityError
+                ].
+                archive isReadable ifFalse:[
+                    self log: ('Archive %1 is not readable!!' bindWith: archive pathName) severity: SeverityError
+                ].
+                (ZipArchive isZipArchive: archive) ifFalse:[
+                    self log: ('Archive %1 does not seem to be a valid .zip archive!!' bindWith: archive pathName) severity: SeverityError
+                ].
+                i := i + 2.            
+            ] ifFalse:[
+                self log: ('Unknown option ''',a,'''') severity: SeverityError.              
+            ]]
+        ].
         self install.
+        Smalltalk exit: 0.
     ] on: Error do:[:ex|
         self log: 'Unexpected error: ', ex description severity: SeverityError
     ]
 
     "Created: / 07-07-2013 / 18:30:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 07-07-2013 / 23:35:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-07-2013 / 01:45:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGInstaller class methodsFor:'documentation'!