I'm trying to implement a restart
command using yargs. I already implemented the start
and stop
commands and all I want to do now, is call these existing commands inside the restart
command.
Unfortunately it does not work by simply using yargs.parse('stop');
yargs.command('start', '', () => {}, (argv) => {
console.log('Starting');
});
yargs.command('stop', '', () => {}, (argv) => {
console.log('Stopping');
});
yargs.command('restart', 'description', () => {}, (argv) => {
yargs.parse('stop');
yargs.parse('start');
});
I also couldn't find anything related in the Github issues or the API documentation. What am I missing?
Thank you!
Yargs helps you build interactive command line tools by parsing arguments and generating an elegant user interface.
Description. Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you: commands and (grouped) options ( my-program. js serve --port=5000 ).
You can simple use JS:
function start(argv) {
console.log('Starting');
}
function stop(argv) {
console.log('Stopping');
}
yargs.command('start', '', () => {}, start);
yargs.command('stop', '', () => {}, stop);
yargs.command('restart', 'description', () => {}, (argv) => {
start(argv);
stop(argv);
});
From a brief look at yargs
API, I don't see another way of doing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With