dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Turn Off Session Functionality #156

Closed austencollins closed 8 years ago

austencollins commented 8 years ago

How can we turn off the session functionality, or immediately exit after a single command?

dthree commented 8 years ago

Use vorpal.parse(), and don't use vorpal.show().

This SO answer should help.

vorpal.show actually starts the interactive CLI. If you don't run it, the app will just exit. vorpal.parse takes the passed in CLI args and runs a given Vorpal command.

If you want to run a command you created on the fly without having the user pass in any args, you can use vorpal.exec('said command').

Does this help?

ekryski commented 8 years ago

I can confirm this works. This is how I am doing it.

   const app = vorpal();

    if (process.argv.length > 2) {
      app.parse(process.argv);
    }
    else {
      app.execSync('help');
      // You could also call app.delimeter('custom:').show()
    }

@dthree you probably close this.

praxiq commented 7 years ago

Maybe something has changed, but this does not work for me. Calling "parse" parses one command, then stays in the CLI, even without a "show."

The code in the SO answer works for me, only because it forgets to call the callback at the end of the command! However, if I type any other command as an argument, it stays in the CLI after parse() completes.