3 var util = require('util');
6 var c = require('../const');
8 var $$ = require('../utils');
9 var HelpFormatter = require('./formatter.js');
12 * new RawDescriptionHelpFormatter(options)
13 * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
15 * Help message formatter which adds default values to argument help.
17 * Only the name of this class is considered a public API. All the methods
18 * provided by the class are considered an implementation detail.
21 function ArgumentDefaultsHelpFormatter(options) {
22 HelpFormatter.call(this, options);
25 util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter);
27 ArgumentDefaultsHelpFormatter.prototype._getHelpString = function (action) {
28 var help = action.help;
29 if (action.help.indexOf('%(defaultValue)s') === -1) {
30 if (action.defaultValue !== c.SUPPRESS) {
31 var defaulting_nargs = [ c.OPTIONAL, c.ZERO_OR_MORE ];
32 if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) {
33 help += ' (default: %(defaultValue)s)';
40 module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter;
43 * new RawDescriptionHelpFormatter(options)
44 * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
46 * Help message formatter which retains any formatting in descriptions.
48 * Only the name of this class is considered a public API. All the methods
49 * provided by the class are considered an implementation detail.
52 function RawDescriptionHelpFormatter(options) {
53 HelpFormatter.call(this, options);
56 util.inherits(RawDescriptionHelpFormatter, HelpFormatter);
58 RawDescriptionHelpFormatter.prototype._fillText = function (text, width, indent) {
59 var lines = text.split('\n');
60 lines = lines.map(function (line) {
61 return $$.trimEnd(indent + line);
63 return lines.join('\n');
65 module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter;
68 * new RawTextHelpFormatter(options)
69 * new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...})
71 * Help message formatter which retains formatting of all help text.
73 * Only the name of this class is considered a public API. All the methods
74 * provided by the class are considered an implementation detail.
77 function RawTextHelpFormatter(options) {
78 RawDescriptionHelpFormatter.call(this, options);
81 util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter);
83 RawTextHelpFormatter.prototype._splitLines = function (text) {
84 return text.split('\n');
87 module.exports.RawTextHelpFormatter = RawTextHelpFormatter;