最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to create a Vorpal application which the command's output goes directly to the terminal, ins

programmeradmin5浏览0评论

When you create Vorpal application, at least from what I see in the docs, it creates it's own shell. First, you enter that shell, and then you start executing mands. Like this:

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

In the above example, the snapshot mand is being executed "inside" the Vorpal shell. It's output doesn't go directly to the terminal.

What I'm looking for is something like this:

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

How can I achieve that with Vorpal?

When you create Vorpal application, at least from what I see in the docs, it creates it's own shell. First, you enter that shell, and then you start executing mands. Like this:

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

In the above example, the snapshot mand is being executed "inside" the Vorpal shell. It's output doesn't go directly to the terminal.

What I'm looking for is something like this:

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

How can I achieve that with Vorpal?

Share Improve this question asked Nov 2, 2015 at 23:58 Andre PenaAndre Pena 59.5k53 gold badges210 silver badges257 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

Yes, you can do this with the vorpal.parse method, which will parse the arguments passed into Vorpal and execute them.

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

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

vorpal.parse(process.argv);

You can have the app exit after pleting the mand simply by omitting vorpal.show(). Because there is no prompt, Node realizes there is nothing left to do, and the process will exit naturally.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论