No Description

added_formatters.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. var util = require('util');
  3. var _ = require('underscore');
  4. _.str = require('underscore.string');
  5. // Constants
  6. var $$ = require('../const');
  7. var HelpFormatter = require('./formatter.js');
  8. /**
  9. * new RawDescriptionHelpFormatter(options)
  10. * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
  11. *
  12. * Help message formatter which adds default values to argument help.
  13. *
  14. * Only the name of this class is considered a public API. All the methods
  15. * provided by the class are considered an implementation detail.
  16. **/
  17. var ArgumentDefaultsHelpFormatter = function ArgumentDefaultsHelpFormatter(options) {
  18. HelpFormatter.call(this, options);
  19. };
  20. util.inherits(ArgumentDefaultsHelpFormatter, HelpFormatter);
  21. ArgumentDefaultsHelpFormatter.prototype._getHelpString = function (action) {
  22. var help = action.help;
  23. if (action.help.indexOf('%(defaultValue)s') === -1) {
  24. if (action.defaultValue !== $$.SUPPRESS) {
  25. var defaulting_nargs = [$$.OPTIONAL, $$.ZERO_OR_MORE];
  26. if (action.isOptional() || (defaulting_nargs.indexOf(action.nargs) >= 0)) {
  27. help += ' (default: %(defaultValue)s)';
  28. }
  29. }
  30. }
  31. return help;
  32. };
  33. module.exports.ArgumentDefaultsHelpFormatter = ArgumentDefaultsHelpFormatter;
  34. /**
  35. * new RawDescriptionHelpFormatter(options)
  36. * new ArgumentParser({formatterClass: argparse.RawDescriptionHelpFormatter, ...})
  37. *
  38. * Help message formatter which retains any formatting in descriptions.
  39. *
  40. * Only the name of this class is considered a public API. All the methods
  41. * provided by the class are considered an implementation detail.
  42. **/
  43. var RawDescriptionHelpFormatter = function RawDescriptionHelpFormatter(options) {
  44. HelpFormatter.call(this, options);
  45. };
  46. util.inherits(RawDescriptionHelpFormatter, HelpFormatter);
  47. RawDescriptionHelpFormatter.prototype._fillText = function (text, width, indent) {
  48. var lines = text.split('\n');
  49. lines = lines.map(function (line) {
  50. return _.str.rtrim(indent + line);
  51. });
  52. return lines.join('\n');
  53. };
  54. module.exports.RawDescriptionHelpFormatter = RawDescriptionHelpFormatter;
  55. /**
  56. * new RawTextHelpFormatter(options)
  57. * new ArgumentParser({formatterClass: argparse.RawTextHelpFormatter, ...})
  58. *
  59. * Help message formatter which retains formatting of all help text.
  60. *
  61. * Only the name of this class is considered a public API. All the methods
  62. * provided by the class are considered an implementation detail.
  63. **/
  64. var RawTextHelpFormatter = function RawTextHelpFormatter(options) {
  65. RawDescriptionHelpFormatter.call(this, options);
  66. };
  67. util.inherits(RawTextHelpFormatter, RawDescriptionHelpFormatter);
  68. RawTextHelpFormatter.prototype._splitLines = function (text) {
  69. return text.split('\n');
  70. };
  71. module.exports.RawTextHelpFormatter = RawTextHelpFormatter;