packages/ant-util-yargs/lib/yargsHelper.js
function attachFailHandler (yargs, handler) {
  yargs.fail((msg, err, usage) => {
    // If failure was handled previously, does nothing.
    if (errorHandled) {
      return;
    }
    handler(msg, err, usage);
    if (errorHandled) {
      // Workaround to avoid yargs from running the command.
      // Since yargs has no mechanisms to any error handler
      // alert the command execution needs to be stopped, and we can't
      // exit the process right away due to possible asynchronous
      // error handlers, we need a way to prevent the command to be
      // ran, since we are handling the error asynchronously.
      // Setting this inner flag will prevent yargs to run the command.
      yargs._setHasOutput();
    }
  });
}
function attachFailHandler (yargs, handler) {
  yargs.fail((msg, err, usage) => {
    // If failure was handled previously, does nothing.
    if (errorHandled) {
      return;
    }
    handler(msg, err, usage);
    if (errorHandled) {
      // Workaround to avoid yargs from running the command.
      // Since yargs has no mechanisms to any error handler
      // alert the command execution needs to be stopped, and we can't
      // exit the process right away due to possible asynchronous
      // error handlers, we need a way to prevent the command to be
      // ran, since we are handling the error asynchronously.
      // Setting this inner flag will prevent yargs to run the command.
      yargs._setHasOutput();
    }
  });
}
function attachFailHandler ( yargs , handler ) { yargs . fail ( ( msg , err , usage ) => { // If failure was handled previously, does nothing. if ( errorHandled ) { return ; } handler ( msg , err , usage ) ; if ( errorHandled ) { // Workaround to avoid yargs from running the command. // Since yargs has no mechanisms to any error handler // alert the command execution needs to be stopped, and we can't // exit the process right away due to possible asynchronous // error handlers, we need a way to prevent the command to be // ran, since we are handling the error asynchronously. // Setting this inner flag will prevent yargs to run the command. yargs . _setHasOutput ( ) ; } } ) ; }
Attaches an error handler into the Yargs instance.

Guarantees the single error handling with the `errorHandled` flag,
which can be set with the `setErrorHandled` function.

@param {!Yargs} yargs The [Yargs]{@link https://github.com/yargs/yargs/blob/master/yargs.js}
instance.
@param {!Function} handler The error handler
Attaches an error handler into the Yargs instance .