I am new to Smalltalk and am trying to figure out how to take in a command line argument as a filename. I've seen this following snippet online:
f := FileStream open: 'fileName' mode: FileStream read
But I want to know how to modify that based on a user's command line input for the fileName. The following is how this project would be compiled and ran:
gst file1.st file2.st file3.st file4.st -f mainFile.st readThisFile.dat addiotnalArg
So how can I pull the name of the user specified file in Smalltalk?
According to https://www.gnu.org/software/smalltalk/manual/gst.html#Invocation you can access the command line arguments that are not interpreted by GNU Smalltalk itself with
Smalltalk arguments. It will be an array that contains those arguments as Strings.Since your readThisFile.dat is the first argument, you can access it with
Smalltalk arguments at: 1and put that into your FileStream constructor message:You can also use
first