3 var util = require('util');
4 var _ = require('lodash');
8 var $$ = require('../const');
10 var HelpFormatter = require('./formatter.js');
13 * new RawDescriptionHelpFormatter(options)
14 * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
16 * Help message formatter which adds default values to argument help.
18 * Only the name of this class is considered a public API. All the methods
19 * provided by the class are considered an implementation detail.
22 var ArgumentDefaultsHelpFormatter = function ArgumentDefaultsHelpFormatter(options) {
23 HelpFormatter.call(this, options);
26 util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter);
28 ArgumentDefaultsHelpFormatter.prototype._getHelpString = function (action) {
29 var help = action.help;
30 if (action.help.indexOf('%(defaultValue)s') === -1) {
31 if (action.defaultValue !== $$.SUPPRESS) {
32 var defaulting_nargs = [$$.OPTIONAL, $$.ZERO_OR_MORE];
33 if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) {
34 help += ' (default: %(defaultValue)s)';
41 module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter;
44 * new RawDescriptionHelpFormatter(options)
45 * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
47 * Help message formatter which retains any formatting in descriptions.
49 * Only the name of this class is considered a public API. All the methods
50 * provided by the class are considered an implementation detail.
53 var RawDescriptionHelpFormatter = function RawDescriptionHelpFormatter(options) {
54 HelpFormatter.call(this, options);
57 util.inherits(RawDescriptionHelpFormatter, HelpFormatter);
59 RawDescriptionHelpFormatter.prototype._fillText = function (text, width, indent) {
60 var lines = text.split('\n');
61 lines = lines.map(function (line) {
62 return _.trimRight(indent + line);
64 return lines.join('\n');
66 module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter;
69 * new RawTextHelpFormatter(options)
70 * new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...})
72 * Help message formatter which retains formatting of all help text.
74 * Only the name of this class is considered a public API. All the methods
75 * provided by the class are considered an implementation detail.
78 var RawTextHelpFormatter = function RawTextHelpFormatter(options) {
79 RawDescriptionHelpFormatter.call(this, options);
82 util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter);
84 RawTextHelpFormatter.prototype._splitLines = function (text) {
85 return text.split('\n');
88 module.exports.RawTextHelpFormatter = RawTextHelpFormatter;