7

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!

1 Answers1

2

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.

justin
  • 3,357
  • 1
  • 23
  • 28