diff --git a/.gitignore b/.gitignore index f3bd253..86400de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ *.sw* node_modules pyret-lang +package-lock.json +.pyret +*.jarr diff --git a/.travis.yml b/.travis.yml index e956092..646e950 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ deploy: provider: npm email: joe.politz@gmail.com api_key: - secure: o8BnblLlSjc0QT89NxDbbaBn/5q1LOFi0JRhiFCqLWw6lwJlEWgg4t6Stnv+/i5sCnnTEnCwdJoB/8OK7nNeQOlfYfwyu/mHGybOOrmTi7+qxL8OlXXDku72BdxTPYmUyB7f8jVDbpt8k3TL76YWpi8s+h9O0sUELM8QVaT2CI2nLNFdmzwErUSOJF5+SP+Eeo2XclQt1BvoM6V/GKb6XBDx4zV+gXinjyCggb6bNPdbvbQ0zXbVrSR0Dxrzuj9E3o16DhPkP8wvNH4ujAfZhDKvZ05MgxMecjUXuBJgTS84L5DS10HapQfB9VgRWvgoa/oeP60xBLDGjc6I66eP3UyxQkjC4AHyuXLkZreL88kjMgD1yGTkIlY7uvEgr/uzj1WqTuc9Ngwiaf/y5sxHmTA1rly68sYalNLAtmA+eGjfWg6qRd6ZuECdrBb+Yurn/VKidOdm1HPuS4OiVN+mKG0KrBDmwcIVt9Vw3RjqmnUDuGB1cGWVUvXwcPou66i8m2a7OMPlpPFbTSbWy3CuoUIasfDx1toGO0W3Pvwrqd1kZ1gMHZKQJKrYxvZixUXxFkT51GlnLdXyrky8So9e697vZx5exWqvVem8t9wHOEAvRxEDi0XIFGh/4jectyDoZGdDa4RjA/au2+B9jVi6kDa0zlmRImg4v7BoZM2hEVY= + secure: "L9yBu/F7D9cRF3vskTB62XEjSuDUDzzKBoAlZdKTCyzwE2gOXarYNFeT+/JKw5LXLlQRWIzj+GAN3/qIogKGN08YdaGpOqcIq4R6UYcGnwXJqr+SWifZhNbAgF9e5sVi4p793X2/XLVe5UGh1bhBGVw8l7Xx9LOWHMbK1REYJhVIIXNHrFY1HmPJKOZW3kTiuccwYDRDkO3WwB3TCHm9ne4FCaWi0juWV9BQjFQMWa9eqSyO4PIBdRWymqYYQyOtZqiWeOMdpwAsipAsJtZ7Y6FhM7PoLiKq+8CLqcb9+LHFp0LyLf4erPO9F224bMJkLgRQyO/gi1KZ1BDEdsKeRh+dE/nWFdu5Cz0+GdbsC/UDLW8xljNULTGVset1rWBtgmiPzsDlcA1VdLxeUfQAVQqC+WJH8ZelcWJ/K9unTHSXKyXAYYDFt2vNEl5G1SSfgArgmi/0VF6dAcappHij68H+ct7ci1lgjnfO/NSmTeebzmOdv0kRPo2O8UQEMHvtcI/ClFbyGJOv23FjGlq5e5MyLsX5WCEyBmgMzqzSWeq11/HAbYd706HsRbkhJLyoCl2o1NUmkkDN607lj/mnJEQUmaVr7jlIR/my6vZKmj97xsp9fkjkwPniPcdIfBmACbOpj3T7KmuXVevRhW/lqsJQEjODFIhpefg1M5O+PI4=" diff --git a/ahoy-world-args.arr b/ahoy-world-args.arr new file mode 100644 index 0000000..b8b617a --- /dev/null +++ b/ahoy-world-args.arr @@ -0,0 +1,7 @@ +import cmdline-lib as CL +args = CL.command-line-arguments() +if args.length() >= 2: + print("Ahoy " + args.get(1) + "!\n") +else: + print("Ahoy world!\n") +end diff --git a/client-lib.js b/client-lib.js index 64f588d..b98deaa 100644 --- a/client-lib.js +++ b/client-lib.js @@ -121,9 +121,9 @@ function start(options) { //process.exit(0); } - function runProgram(path) { - log("Executing program: ", path); - const proc = childProcess.spawn("node", [path], {stdio: 'inherit'}); + function runProgram(path, argv) { + log("Executing program: ", path, " with ", argv); + const proc = childProcess.spawn("node", [path].concat(argv), {stdio: 'inherit'}); proc.on('close', function(code) { process.exit(code); }); @@ -176,12 +176,15 @@ function start(options) { else if(parsed.type === "compile-success") { log("Successful compile response"); if(!options.meta.norun) { - process.nextTick(() => runProgram(options["pyret-options"]["outfile"])); + var argv = options["_unknown"] || []; + if (argv.length > 0 && argv[0] == "--") { + argv = argv.slice(1); + } + process.nextTick(() => runProgram(options["pyret-options"]["outfile"], argv)); } } }); - var forMessage = { command: "compile", compileOptions: JSON.stringify(options['pyret-options']) }; client.send(JSON.stringify(forMessage)); }); diff --git a/package.json b/package.json index f75a14d..7ca998c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pyret-npm", - "version": "0.0.17", + "version": "0.0.28-alpha", "description": "The CLI for the Pyret programming language", "files": [ "pyret.js", diff --git a/pyret.js b/pyret.js index c3ab701..4b1cf24 100755 --- a/pyret.js +++ b/pyret.js @@ -30,7 +30,6 @@ const usages = [ '', '', ' This command compiled and ran {underline ahoy-world.arr}. The first time, this will take a few seconds as a server starts up in the background, in order to make future compiles fast.', - '', '', ' It\'s worth noting that the file is compiled into a standalone JavaScript file with the {underline .jarr} extension:', @@ -42,7 +41,34 @@ const usages = [ '', '', ' Most uses (e.g. for homework) only need to use the {bold pyret} command directly on {underline .arr} files, but there are several other options that can be provided.', - + '', + '', + ' You can pass arguments to your pyret program by adding {bold --} followed by the command-line arguments:', + ] + }, + { + content: { + options: { + noTrim: true + }, + data: [ + {col: '$ cat ahoy-world-args.arr'}, + {col: 'import cmdline-lib as CL'}, + {col: 'args = CL.command-line-arguments()'}, + {col: 'if args.length() >= 2:'}, + {col: ' print("Ahoy " + args.get(1) + "!\\\\n")'}, + {col: 'else:'}, + {col: ' print("Ahoy world!\\\\n")'}, + {col: 'end'}, + {col: '$ pyret -qk ahoy-world-args.arr {bold -- Captain}'}, + {col: 'Ahoy Captain!'}, + ] + } + }, + { + content: [ + '', + ' This command suppresses the progress indication, disables checks, and passes one command-line argument to {underline ahoy-world-args.arr}: {bold "Captain"} (index 1). The {bold "--"} argument is only needed so that {bold pyret} does not interpret it. It should be noted that the index 0 argument contains the path to the compiled {underline .jarr} file.', ] }, { @@ -253,7 +279,7 @@ function printVersion() { } try { - options = commandLineArgs(optionDefinitions); + options = commandLineArgs(optionDefinitions, {stopAtFirstUnknown: true}); if(options.meta.help) { printUsage(); process.exit(0); @@ -276,5 +302,9 @@ if(!options["pyret-options"]["outfile"] && options["pyret-options"]["program"]) } } -pyretClient.start(options); +if (options["_unknown"] && !options["pyret-options"]["program"]) { + printUsage(); + process.exit(1); +} +pyretClient.start(options);