如何将命令行参数传递给Deno? [英] How to pass command line arguments to Deno?
本文介绍了如何将命令行参数传递给Deno?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Deno 应用,我希望将一些命令行参数传递给它。我搜索了手册,但一无所获。
I have a Deno app, that I wish to pass some command line args to. I searched the manual, but found nothing.
我尝试使用与Node.js中相同的命令,假设它们可能为std库共享了一些命令,但效果不佳。
I tried to use the same commands used in Node.js, assuming they might be sharing some for the std libraries, but it didn't work as well.
var args = process.argv.slice(2);
// Uncaught ReferenceError: process is not defined
有任何建议吗?
推荐答案
您可以使用 Deno.args
访问Deno中的命令行参数。
You can use Deno.args
to access the command line arguments in Deno.
要尝试创建文件test.ts:
To try it create a file test.ts :
console.log(Deno.args);
并使用 deno run test.ts firstArgument secondArgument $ c运行它$ c>
它将返回一组传递的参数:
It will return you with an array of the passed args:
$ deno run test.ts firstArgument secondArgument
[ "firstArgument", "secondArgument" ]
这篇关于如何将命令行参数传递给Deno?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文