是否可以创建一个 Vorpal 应用程序,命令的输出直接进入终端,而不是它自己的 shell?

Is it possible to create a Vorpal application which the command's output goes directly to the terminal, instead of it's own shell?

当您创建 Vorpal 应用程序时,至少从我在文档中看到的内容来看,它会创建自己的 shell。首先,输入 shell,然后开始执行命令。像这样:

user@computer: quotr
quotr$
quotr$ snapshot
You triggered `snapshot`.
quotr$

在上面的例子中,正在执行 snapshot 命令 "inside" Vorpal shell。它的输出不直接进入终端。

我要找的是这样的:

user@computer: quotr snapshot
You triggered `snapshot`.
user@computer:

我如何使用 Vorpal 实现这一目标?

是的,您可以使用 vorpal.parse 方法执行此操作,该方法将解析传递给 Vorpal 的参数并执行它们。

var vorpal = require('vorpal')();

vorpal
  .command('snapshot')
  .action(function (args, cb) {
    this.log('You triggered `snapshot`.');
    cb();
  });

vorpal.parse(process.argv);

您只需省略 vorpal.show() 即可在完成命令后退出应用程序。因为没有提示,Node意识到没什么可做的,进程自然退出。