#!/usr/bin/env node
/**
 * An NPM script which will be run from scripts in package.json.
 *
 * @copyright Copyright 2016 Kevin Locke <kevin@kevinlocke.name>
 * @license MIT
 */

'use strict';

/** Entry point for this command.
 *
 * @param {!Array<string>} args Command-line arguments.
 * @param {CommandOptions=} options Options.
 * @param {?function(Error, number=)=}
 * callback Callback for the exit code or an <code>Error</code>.
 * @return {Promise<number>|undefined} If <code>callback</code> is not given,
 * a <code>Promise</code> with the exit code or <code>Error</code>.
 */
function scriptname(args, options, callback) {
  if (!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }

  if (!callback) {
    return new Promise((resolve, reject) => {
      scriptname(args, (err, result) => {
        if (err) { reject(err); } else { resolve(result); }
      });
    });
  }

  if (typeof callback !== 'function') {
    throw new TypeError('callback must be a function');
  }

  return undefined;
}

module.exports = scriptname;

if (require.main === module) {
  // This file was invoked directly.
  /* eslint-disable no-process-exit */
  const mainOptions = {
    in: process.stdin,
    out: process.stdout,
    err: process.stderr,
  };
  scriptname(process.argv, mainOptions, (err, code) => {
    if (err) {
      if (err.stdout) { process.stdout.write(err.stdout); }
      if (err.stderr) { process.stderr.write(err.stderr); }
      process.stderr.write(`${err.name}: ${err.message}\n`);

      code = typeof err.code === 'number' ? err.code : 1;
    }

    process.exit(code);
  });
}

@@ -215,15 +215,14 @@
 his 
-command
+script
 .%0A *
@@ -233,17 +233,16 @@
 @param %7B
-!
 Array%3Cst
@@ -288,16 +288,17 @@
 @param %7B
+!
 CommandO
@@ -303,17 +303,16 @@
 dOptions
-=
 %7D option
@@ -333,17 +333,16 @@
 @param %7B
-?
 function
@@ -346,204 +346,40 @@
 ion(
-Error, number=)=%7D%0A * callback Callback for the exit code or an %3Ccode%3EError%3C/code%3E.%0A * @return %7BPromise%3Cnumber%3E%7Cundefined%7D If %3Ccode%3Ecallback%3C/code%3E is not given,%0A * a %3Ccode%3EPromise%3C/code%3E
+number)%7D callback Callback
  with 
-the 
 exit
@@ -387,30 +387,8 @@
 code
- or %3Ccode%3EError%3C/code%3E
 .%0A *
@@ -440,420 +440,8 @@
 ) %7B%0A
-  if (!callback && typeof options === 'function') %7B%0A    callback = options;%0A    options = null;%0A  %7D%0A%0A  if (!callback) %7B%0A    return new Promise((resolve, reject) =%3E %7B%0A      scriptname(args, (err, result) =%3E %7B%0A        if (err) %7B reject(err); %7D else %7B resolve(result); %7D%0A      %7D);%0A    %7D);%0A  %7D%0A%0A  if (typeof callback !== 'function') %7B%0A    throw new TypeError('callback must be a function');%0A  %7D%0A%0A  return undefined;%0A
 %7D%0A%0Am
@@ -544,487 +544,161 @@
 %0A  /
-* eslint-disable no-
+/ Note:  Could pass 
 process
--
+.
 exit 
-*/%0A  const mainOptions = %7B%0A    in: process.stdin,%0A    out: process.stdout,%0A    err: process.stderr,%0A  %7D;%0A  scriptname(process.argv, mainOptions, (err, code) =%3E %7B%0A    if (err) %7B%0A      if (err.stdout) %7B process.stdout.write(err.stdout); %7D%0A      if (err.stderr) %7B process.stderr.write(err.stderr); %7D%0A      process.stderr.write(%60$%7Berr.name%7D: $%7Berr.message%7D%5Cn%60);%0A%0A      code = typeof err.code === 'number' ? err.code : 1;%0A    %7D%0A%0A    process.
+as callback to force immediate exit.%0A  scriptname(process.argv, process, (exitCode) =%3E %7B%0A    process.exitCode = 
 exit
-(c
+C
 ode
-)
 ;%0A  

Use bin/cmd.js conventions