[squeak-dev] Improving command line argument processing

David T. Lewis lewis at mail.msen.com
Mon Jun 8 23:26:04 UTC 2020


Hi Subbu,

On Tue, Jun 09, 2020 at 12:56:03AM +0530, K K Subbu wrote:
> On 08/06/20 4:23 am, David T. Lewis wrote:
> >   $ squeak squeak.image -- arg1 arg2 arg3 "do not treat arg1 as a script"
> 
> This should result in an error. Unix convention is to prefix - or -- to 
> options and therefore -- is a special marker to terminate option 
> processing and allow arguments beginning with -. So you can type "grep 
> -- -v" to search for -v in files. In our case, squeak.image does not 
> begin with - and so option processing stops automatically. Anything 
> after the image file becomes the arguments for the image and not the 
> platform vm. So there is no need to use -- for disambiguation.
> 
> >   $ squeak script.st arg1 arg2 arg3 ==> error image not found
> 
> On Unix, the env variable SQUEAK_IMAGE is checked if the first argument 
> is not an image file. If the variable is not set, then the image file is 
> assumed to be "squeak.image". So this will be a valid invocation:
> 
>      $ squeak ${SQUEAK_IMAGE:-squeak.image} script.st arg1 arg2 arg3
>

Exactly so. The '--' terminates further processing of the argument list,
and passes the remainder to the image for further interpretation.

According to the -help message from the VM:

$ squeak -help
Usage: /usr/local/lib/squeak/4.19.1-3780/squeakvm [<option>...] [<imageName> [<argument>...]]
       /usr/local/lib/squeak/4.19.1-3780/squeakvm [<option>...] -- [<argument>...]

And a note toward the end of the help message says:

  Precede <arguments> by `--' to use default image.

The above does not tell you explicitly how to parse this:

  $ squeak squeak.image -- arg1 arg2 arg3
 
But if you consider that the VM is parsing the command line in the normal
manner up to the '--' token, and then passing the rest on the the image
as arguments, then the behavior seems quite reasonable.

The need for '--' for disambiguation remains, partly because of the Squeak
convention of allowing an optional start script to be specified after the
image name.  You need to have some way of determining if 'arg1' was intended
as an argument for the image to process, or if it was intended as the name
of a script document to be evaluated at image startup time.

Dave
 


More information about the Squeak-dev mailing list