lib/util/setupCLI.js
function GetCommandUsage(execName, packageJson, cmdSpec, args) {
  const argSpec = cmdSpec.argSpec || [];
  const optStr = argSpec.length ? ' [options]' : '';
  const header = `\
Usage:   ${execName} ${cmdSpec.name}${optStr}
Purpose: ${cmdSpec.desc}
Options: ${argSpec.length ? '' : 'none.'}`;

  const usageTableRows = _.map(cmdSpec.argSpec, (argDef) => {
    const dashify = flag => (flag.length === 1 ? `-${col.primary(flag)}` : `--${col.primary(flag)}`);
    const lhs = _.map(argDef.flags, dashify).join(', ');
    const rhs = argDef.desc || '';
    return [lhs, rhs, argDef];
  });

  const firstColWidth = _.max(
    _.map(usageTableRows, row => stripAnsi(row[0]).length)) + 1;

  const body = _.map(usageTableRows, (row) => {
    const rhsLines = row[1].split(/\n/mg);
    const firstRhsLine = rhsLines[0];
    rhsLines.splice(0, 1);

    const lhsSpacer = new Array((firstColWidth - stripAnsi(row[0]).length) + 1).join(' ');
    const paddedLhs = `${lhsSpacer}${row[0]}`;
    const firstLine = `${paddedLhs}: ${firstRhsLine}`;

    const skipLeft = new Array(firstColWidth + 1).join(' ');
    const paddedRhs = rhsLines.length ? _.map(rhsLines, line => `${skipLeft}${line}`).join('\n') : '';

    const argDef = row[2];
    let curVal = _.find(argDef.flags, flag => (flag in args ? args[flag] : null));
    if (!curVal) curVal = argDef.defVal || argDef.default || '';
    if (curVal) {
      curVal = `${skipLeft}  ${col.dim('Current:')} "${col.primary(curVal)}"`;
    }
    return _.filter([
      firstLine,
      paddedRhs,
      curVal,
    ]).join('\n');
  }).join('\n\n');

  return `\
${header}
${body}
`;
}
function GetCommandUsage(execName, packageJson, cmdSpec, args) {
  const argSpec = cmdSpec.argSpec || [];
  const optStr = argSpec.length ? ' [options]' : '';
  const header = `\
Usage:   ${execName} ${cmdSpec.name}${optStr}
Purpose: ${cmdSpec.desc}
Options: ${argSpec.length ? '' : 'none.'}`;

  const usageTableRows = _.map(cmdSpec.argSpec, (argDef) => {
    const dashify = flag => (flag.length === 1 ? `-${col.primary(flag)}` : `--${col.primary(flag)}`);
    const lhs = _.map(argDef.flags, dashify).join(', ');
    const rhs = argDef.desc || '';
    return [lhs, rhs, argDef];
  });

  const firstColWidth = _.max(
    _.map(usageTableRows, row => stripAnsi(row[0]).length)) + 1;

  const body = _.map(usageTableRows, (row) => {
    const rhsLines = row[1].split(/\n/mg);
    const firstRhsLine = rhsLines[0];
    rhsLines.splice(0, 1);

    const lhsSpacer = new Array((firstColWidth - stripAnsi(row[0]).length) + 1).join(' ');
    const paddedLhs = `${lhsSpacer}${row[0]}`;
    const firstLine = `${paddedLhs}: ${firstRhsLine}`;

    const skipLeft = new Array(firstColWidth + 1).join(' ');
    const paddedRhs = rhsLines.length ? _.map(rhsLines, line => `${skipLeft}${line}`).join('\n') : '';

    const argDef = row[2];
    let curVal = _.find(argDef.flags, flag => (flag in args ? args[flag] : null));
    if (!curVal) curVal = argDef.defVal || argDef.default || '';
    if (curVal) {
      curVal = `${skipLeft}  ${col.dim('Current:')} "${col.primary(curVal)}"`;
    }
    return _.filter([
      firstLine,
      paddedRhs,
      curVal,
    ]).join('\n');
  }).join('\n\n');

  return `\
${header}
${body}
`;
}
function GetCommandUsage ( execName , packageJson , cmdSpec , args ) { const argSpec = cmdSpec . argSpec || [ ] ; const optStr = argSpec . length ? ' [options]' : '' ; const header = ` \
 ${ execName } ${ cmdSpec . name } ${ optStr } ${ cmdSpec . desc } ${ argSpec . length ? '' : 'none.' } ` ; const usageTableRows = _ . map ( cmdSpec . argSpec , ( argDef ) => { const dashify = flag => ( flag . length === 1 ? ` ${ col . primary ( flag ) } ` : ` ${ col . primary ( flag ) } ` ) ; const lhs = _ . map ( argDef . flags , dashify ) . join ( ', ' ) ; const rhs = argDef . desc || '' ; return [ lhs , rhs , argDef ] ; } ) ; const firstColWidth = _ . max ( _ . map ( usageTableRows , row => stripAnsi ( row [ 0 ] ) . length ) ) + 1 ; const body = _ . map ( usageTableRows , ( row ) => { const rhsLines = row [ 1 ] . split ( / \n / mg ) ; const firstRhsLine = rhsLines [ 0 ] ; rhsLines . splice ( 0 , 1 ) ; const lhsSpacer = new Array ( ( firstColWidth - stripAnsi ( row [ 0 ] ) . length ) + 1 ) . join ( ' ' ) ; const paddedLhs = ` ${ lhsSpacer } ${ row [ 0 ] } ` ; const firstLine = ` ${ paddedLhs } ${ firstRhsLine } ` ; const skipLeft = new Array ( firstColWidth + 1 ) . join ( ' ' ) ; const paddedRhs = rhsLines . length ? _ . map ( rhsLines , line => ` ${ skipLeft } ${ line } ` ) . join ( '\n' ) : '' ; const argDef = row [ 2 ] ; let curVal = _ . find ( argDef . flags , flag => ( flag in args ? args [ flag ] : null ) ) ; if ( ! curVal ) curVal = argDef . defVal || argDef . default || '' ; if ( curVal ) { curVal = ` ${ skipLeft } ${ col . dim ( 'Current:' ) } ${ col . primary ( curVal ) } ` ; } return _ . filter ( [ firstLine , paddedRhs , curVal , ] ) . join ( '\n' ) ; } ) . join ( '\n\n' ) ; return ` \
 ${ header } ${ body } ` ; }
Get command-specific help.
Get command - specific help .