react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / lib / help / added_formatters.js
80728 views'use strict';12var util = require('util');3var _ = require('lodash');456// Constants7var $$ = require('../const');89var HelpFormatter = require('./formatter.js');1011/**12* new RawDescriptionHelpFormatter(options)13* new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})14*15* Help message formatter which adds default values to argument help.16*17* Only the name of this class is considered a public API. All the methods18* provided by the class are considered an implementation detail.19**/2021var ArgumentDefaultsHelpFormatter = function ArgumentDefaultsHelpFormatter(options) {22HelpFormatter.call(this, options);23};2425util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter);2627ArgumentDefaultsHelpFormatter.prototype._getHelpString = function (action) {28var help = action.help;29if (action.help.indexOf('%(defaultValue)s') === -1) {30if (action.defaultValue !== $$.SUPPRESS) {31var defaulting_nargs = [$$.OPTIONAL, $$.ZERO_OR_MORE];32if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) {33help += ' (default: %(defaultValue)s)';34}35}36}37return help;38};3940module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter;4142/**43* new RawDescriptionHelpFormatter(options)44* new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})45*46* Help message formatter which retains any formatting in descriptions.47*48* Only the name of this class is considered a public API. All the methods49* provided by the class are considered an implementation detail.50**/5152var RawDescriptionHelpFormatter = function RawDescriptionHelpFormatter(options) {53HelpFormatter.call(this, options);54};5556util.inherits(RawDescriptionHelpFormatter, HelpFormatter);5758RawDescriptionHelpFormatter.prototype._fillText = function (text, width, indent) {59var lines = text.split('\n');60lines = lines.map(function (line) {61return _.trimRight(indent + line);62});63return lines.join('\n');64};65module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter;6667/**68* new RawTextHelpFormatter(options)69* new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...})70*71* Help message formatter which retains formatting of all help text.72*73* Only the name of this class is considered a public API. All the methods74* provided by the class are considered an implementation detail.75**/7677var RawTextHelpFormatter = function RawTextHelpFormatter(options) {78RawDescriptionHelpFormatter.call(this, options);79};8081util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter);8283RawTextHelpFormatter.prototype._splitLines = function (text) {84return text.split('\n');85};8687module.exports.RawTextHelpFormatter = RawTextHelpFormatter;888990