title: Checking command arguments for errors from gulpfile using yargs
body: <p>I have a gulpfile for an Angular app that I'm trying to catch errors in the arguments.</p>
  
  <pre><code>var gulp = require('gulp');
  var args = require('yargs').argv;
  ...
  var isProduction = args.env === 'production';
  var useHttpBackend = args.api === 'mock';
  </code></pre>
  
  <p>In my gulpfile I have various tasks that use 'isProduction' and 'useHttpBackend' to determine what to do with files, assets, etc.</p>
  
  <p>The two main tasks are 'default' and 'build'.</p>
  
  <pre><code>// Starts test server and sets up watch and livereload
  gulp.task('default', function() {
    gulp.start('connect', 'build', 'watch');
  });
  
  ...
  
  gulp.task('build', ['clean'], function() {
    gulp.start('assets', 'app', 'stylus', 'index', 'templates', 'vendor');
  });
  </code></pre>
  
  <p>There's basically two commands that can be run:</p>
  
  <pre><code># continuous incremental rebuild + web server + api mocking
  ./node_modules/.bin/gulp --api mock
  ...
  # build for production (optimized version)
  ./node_modules/.bin/gulp --env production
  </code></pre>
  
  <p>I'm not even sure all this info is needed for my question, but how can I check arguments in the commands? When running the first command with '-api' (single-hyphen) instead of '--api' (double-hyphen) tasks are still run but the app does not run properly because args are not recognized. How can I ouput --help or an error in this situation?</p>