admin管理员组

文章数量:1356768

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.

本文标签: