[squeak-dev] Improving command line argument processing
K K Subbu
kksubbu.ml at gmail.com
Tue Jun 9 05:51:21 UTC 2020
On 09/06/20 4:56 am, David T. Lewis wrote:
> 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.
Ha! I now see the cause for confusion. Here arguments refers to image's
arguments not vm's options.
>
> 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 vm option parsing stops when at the first word which does not begin
with - or -- *which ever occurs earlier*. In your example, vm options
will terminate at squeak.image and not see the -- coming after it. The
-- will parse as a image arg word and passed as such to the image.
As best as I could make out, the usage syntax is:
<vm> <vmopt>* [--] [<file.image>] <image-args>*
<vmopt> = -<letter> | --<word>
The [--] is needed to mark the end of <vmopt> only when <image> or the
first <image-arg> begins with - (unlikely in interactive but possible in
shell scripts). The vm does check if the first non-option word ends in
*.image. If not, it uses ${SQUEAK_IMAGE:-squeak.image} and passes the
remaining args to this image.
> 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.
Image arg parsing is handled within the image and does not have to use
the Unix convention. I wouldn't recommend it because Squeak Image runs
on multiple platforms. The convention would be to check if the first arg
is a registered command word (e.g. eval st) or a chunk file (*.st) and
then let the command/script parse the rest of the arguments.
Regards .. Subbu
More information about the Squeak-dev
mailing list
|