function formatOption()

in src/argsParser.js [16:46]


function formatOption(option) {
  let text = '  ';
  text += option.abbr ? `-${option.abbr}, ` : '    ';
  text += `--${option.flag ? '(no-)' : ''}${option.full}`;
  if (option.choices) {
    text += `=${option.choices.join('|')}`;
  } else if (option.metavar) {
    text += `=${option.metavar}`;
  }
  if (option.list) {
    text += ' ...';
  }
  if (option.defaultHelp || option.default !== undefined || option.help) {
    text += '  ';
    if (text.length < 32) {
      text += ' '.repeat(32 - text.length);
    }
    const textLength = text.length;
    if (option.help) {
      text += option.help;
    }
    if (option.defaultHelp || option.default !== undefined) {
      if (option.help) {
        text += '\n';
      }
      text += `${' '.repeat(textLength)}(default: ${option.defaultHelp || option.default})`;
    }
  }

  return text;
}