[squeak-dev] Improving command line argument processing

David T. Lewis lewis at mail.msen.com
Mon Jun 8 18:22:29 UTC 2020


Hi Marcel,

> Well, it would be nice to also work with "/arg" not just "--arg" on the Windows CMD shell. ;-)

I think that is a slightly different topic. The '--' that I was referring
to is a token (with whitespace around the '--' string) that can appear
in the middle of a command line. I think this usage is based on some
old unix conventions, and it basically tells the VM executable to stop
processing arguments and pass everything else remaining on the command
line to the image itself.

This convention allows you to explicitly separate the VM parameters (the
ones before the '--' token) from the remaining parameters that should be
passed along to the image. It also allows you to write a command line that
tells the VM "do not treat the next argument as a start script, just pass
it along to the image". And that in turn is why I think that the
readDocumentAtStartup preference is not longer required once we clean
up the argument processing issues.

I just took a look at the Windows and Unix VMs, and they both do a very
similar job of parsing VM and image parameters. But the Windows VM does
*not* have the bug that I mentioned, so if we want to fix that bug we
would only need to address it in the unix VM.

With respect to arguments identified by '-a value' or '--arg value' or
'/arg value'' I think that might be an issue for the VM itself. If you
wanted the Windows VM to accept VM arguments like '/arg', that would be
something to implement in the Windows VM. And if you wanted to so something
similar in image for handling the parameters passed to the image, you
could do that also (at a later time I guess).

For parsing argument lists in the image, I did some googling and was
reminded that Ian Piumarta apparently implemented a Smalltalk version
of the ancient unix standard getopt(). That would be a reasonable thing
for us to include in the image, but I don't know what became of the
actual code.

Dave


On Mon, Jun 08, 2020 at 11:49:24AM +0200, Marcel Taeumel wrote:
> Hi Dave!
> 
> Thanks for looking into this! :-)
> 
> >??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.
> 
> Well, it would be nice to also work with "/arg" not just "--arg" on the Windows CMD shell. ;-)
> 
> Best,
> Marcel
> Am 08.06.2020 00:53:26 schrieb David T. Lewis <lewis at mail.msen.com>:
> 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