[squeak-dev] Improving command line argument processing

David T. Lewis lewis at mail.msen.com
Sun Jun 7 22:53:17 UTC 2020


Background:

Motivated by the recent "Image not startable after save" discussion, I was
looking to see if there might be a way to inject a startup patch script,
specified as a command line option, that would be evaluated prior to any
of the processStartupList: processing.

That led me to notice that '--' handling in the command line is currently
broken in trunk (see the -help message from the VM for intended behavior).

So I fixed that, but then I noticed that argument processing was generally
all bolloxed up and worked inconsistently.

So I fixed that, thinking that I might put it in the inbox. But then I
noticed that VM is also inconsistent with respect to passing the '--' token
to the image in the VM parameters.

So I fixed that, thinking that I could do a pull request to opensmalltalk-vm
to get that resolved.

Then in noticed that the readDocumentAtStartup preference serves no useful
purpose once the argument processing is fixed, so I eliminated use of the
preference, so it can be deprecated and removed at a later date.

But in total, this is a a lot of change to something that never working
right in the first place, so I would like to summarize my idea of how of
I think it *should* work for review before posting any code. If this
seems reasonable, I'll put my changes in the inbox.

Here is how I think it should work, showing first a unix command line, and
then the expect arguments as seen in the image:

  $ squeak squeak.image -- arg1 arg2 arg3 "do not treat arg1 as a script"
  Smalltalk arguments ==> #('arg1' 'arg2' 'arg3')
  (1 to: 4) collect: [:i | Smalltalk argumentAt: i ] ==> #('arg1' 'arg2' 'arg3' nil)

  $ squeak squeak.image script.st -- arg1 arg2 arg3 "script.st runs"
  Smalltalk arguments ==> #('arg1' 'arg2' 'arg3')
  (1 to: 4) collect: [:i | Smalltalk argumentAt: i ] ==> #('arg1' 'arg2' 'arg3' nil)

  $ squeak squeak.image -- script.st arg1 arg2 arg3 "script.st does not run"
  Smalltalk arguments ==> #('start.st' 'arg1' 'arg2' 'arg3')
  (1 to: 5) collect: [:i | Smalltalk argumentAt: i ] ==> #('start.st' 'arg1' 'arg2' 'arg3' nil)

  $ squeak squeak.image script.st arg1 arg2 arg3 "script.st runs"
  Smalltalk arguments ==> #('arg1' 'arg2' 'arg3')
  (1 to: 4) collect: [:i | Smalltalk argumentAt: i ] ==> #('arg1' 'arg2' 'arg3' nil)

  $ squeak script.st arg1 arg2 arg3 ==> error image not found

  $ squeak script.st -- arg1 arg2 arg3 ==> error image not found

  "Preferred bahaviour, but VM patch required"
  $ squeak -- arg1 arg2 arg3 "use default image name squeak.image and no start script"
  Smalltalk arguments ==> #('arg1' 'arg2' 'arg3')
  (1 to: 4) collect: [:i | Smalltalk argumentAt: i ] ==> #('arg1' 'arg2' 'arg3' nil)
 
  "Without VM patch, this is the expected (but not desirable) behavior, because
  the VM fails to provide '--' in vmParameters in this case only. Note that the 
  current workaround is simply to specify the image name on the command line."
  $ squeak -- arg1 arg2 arg3 ==> Error: no content to install
  Smalltalk arguments ==> #('arg2' 'arg3')
  (1 to: 4) collect: [:i | Smalltalk argumentAt: i ] #('arg2' 'arg3' nil nil)

Dave


More information about the Squeak-dev mailing list