3

Scripts that come with GNU Smalltalk installation use the following code to parse command line arguments:

    Smalltalk
        arguments: '-h|--help --usage --version'
        do: [ :opt :arg |

        opt = 'help' ifTrue: [ do something ... ].

        opt = 'usage' ifTrue: [ do something ... ].

        opt = 'version' ifTrue: [ do something ... ]
        ]

        ifError: [ do something ... ].
]

The thing that troubles me is this:

Smalltalk arguments: '-h|--help --usage --version'

I don't understand what is going on there. I know that:

Smalltalk arguments

returns array of strings passed to the command line, but in this case, it looks like method is being called with argument '-h|--help --usage --version'? I wonder how this string is compared to an arguments array and how command line switches are extracted? A link to a documentation or explanation would be very valuable.

ljubak
  • 123
  • 1
  • 1
  • 5
  • 1
    google arguments:do:ifError: gst documentation is inline https://www.gnu.org/software/smalltalk/manual-base/html_node/SystemDictionary_002dcommand_002dline.html – aka.nice Jan 09 '17 at 08:27
  • 1
    in other words, the parameter passed after the arguments: key are not the arguments coming from the command line, but a pattern. See implementation i.e. near end of https://fossies.org/linux/smalltalk/kernel/Getopt.st – aka.nice Jan 09 '17 at 09:26

0 Answers0