brownplt / pyret-npm

Apache License 2.0
4 stars 2 forks source link

How to Pass Command Line Arguments? #4

Open jrg94 opened 11 months ago

jrg94 commented 11 months ago

I currently maintain the Sample Programs repo, and I'm looking to expand our collection of Pyret scripts. I quite like the language, but I'm running into an issue where I can't seem to figure out how to provide command line arguments. We use this npm package in a Docker image, so we can run Pyret scripts. Is there a way to pass arguments to this compiler? Here are all the files and whatnot for reference:

A simple script that I'd like to implement is capitalize which just capitalizes the first letter of a user's input and prints the result. The script itself is pretty straightforward to write, but I can't figure out how to get something like the following to work:

pyret -qk capitalize.arr "capitalize"

Unfortunately, the command above produces the help dialog instead. After digging through docs, I was unable to solve this problem. Others seem to be having the same issue. Any help would be greatly appreciated!

rzuckerm commented 9 months ago

@jrg94 Actually, I think this can be done like this:

pyret -qkc capitalize.arr
node capitalize.arr "capitalize"

The first command compiles capitalize.arr to capitalize.jarr, which can be run by node with command-line arguments. You can parse the command-line arguments using this to get the command-line arguments:

import cmdline-lib as CL
args = CL.command-line-arguments()
jrg94 commented 9 months ago

Clever! I like this solution.