3c99c4a1fc1826dc3632f08ef33d9c059bdccb9e
[platform/framework/web/crosswalk-tizen.git] /
1 'use strict';
2
3 var util    = require('util');
4 var _       = require('lodash');
5
6
7 // Constants
8 var $$ = require('../const');
9
10 var HelpFormatter = require('./formatter.js');
11
12 /**
13  * new RawDescriptionHelpFormatter(options)
14  * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
15  *
16  * Help message formatter which adds default values to argument help.
17  *
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.
20  **/
21
22 var ArgumentDefaultsHelpFormatter = function ArgumentDefaultsHelpFormatter(options) {
23   HelpFormatter.call(this, options);
24 };
25
26 util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter);
27
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)';
35       }
36     }
37   }
38   return help;
39 };
40
41 module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter;
42
43 /**
44  * new RawDescriptionHelpFormatter(options)
45  * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
46  *
47  * Help message formatter which retains any formatting in descriptions.
48  *
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.
51  **/
52
53 var RawDescriptionHelpFormatter = function RawDescriptionHelpFormatter(options) {
54   HelpFormatter.call(this, options);
55 };
56
57 util.inherits(RawDescriptionHelpFormatter, HelpFormatter);
58
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);
63     });
64   return lines.join('\n');
65 };
66 module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter;
67
68 /**
69  * new RawTextHelpFormatter(options)
70  * new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...})
71  *
72  * Help message formatter which retains formatting of all help text.
73  *
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.
76  **/
77
78 var RawTextHelpFormatter = function RawTextHelpFormatter(options) {
79   RawDescriptionHelpFormatter.call(this, options);
80 };
81
82 util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter);
83
84 RawTextHelpFormatter.prototype._splitLines = function (text) {
85   return text.split('\n');
86 };
87
88 module.exports.RawTextHelpFormatter = RawTextHelpFormatter;