store.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*:nodoc:*
  2. * class ActionStore
  3. *
  4. * This action just stores the argument’s value. This is the default action.
  5. *
  6. * This class inherited from [[Action]]
  7. *
  8. **/
  9. 'use strict';
  10. var util = require('util');
  11. var Action = require('../action');
  12. // Constants
  13. var c = require('../const');
  14. /*:nodoc:*
  15. * new ActionStore(options)
  16. * - options (object): options hash see [[Action.new]]
  17. *
  18. **/
  19. var ActionStore = module.exports = function ActionStore(options) {
  20. options = options || {};
  21. if (this.nargs <= 0) {
  22. throw new Error('nargs for store actions must be > 0; if you ' +
  23. 'have nothing to store, actions such as store ' +
  24. 'true or store const may be more appropriate');
  25. }
  26. if (typeof this.constant !== 'undefined' && this.nargs !== c.OPTIONAL) {
  27. throw new Error('nargs must be OPTIONAL to supply const');
  28. }
  29. Action.call(this, options);
  30. };
  31. util.inherits(ActionStore, Action);
  32. /*:nodoc:*
  33. * ActionStore#call(parser, namespace, values, optionString) -> Void
  34. * - parser (ArgumentParser): current parser
  35. * - namespace (Namespace): namespace for output data
  36. * - values (Array): parsed values
  37. * - optionString (Array): input option string(not parsed)
  38. *
  39. * Call the action. Save result in namespace object
  40. **/
  41. ActionStore.prototype.call = function (parser, namespace, values) {
  42. namespace.set(this.dest, values);
  43. };