l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

store.js (1350B)


      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 
     11 var util = require('util');
     12 
     13 var Action = require('../action');
     14 
     15 // Constants
     16 var c = require('../const');
     17 
     18 
     19 /*:nodoc:*
     20  * new ActionStore(options)
     21  * - options (object): options hash see [[Action.new]]
     22  *
     23  **/
     24 var ActionStore = module.exports = function ActionStore(options) {
     25   options = options || {};
     26   if (this.nargs <= 0) {
     27     throw new Error('nargs for store actions must be > 0; if you ' +
     28         'have nothing to store, actions such as store ' +
     29         'true or store const may be more appropriate');
     30 
     31   }
     32   if (typeof this.constant !== 'undefined' && this.nargs !== c.OPTIONAL) {
     33     throw new Error('nargs must be OPTIONAL to supply const');
     34   }
     35   Action.call(this, options);
     36 };
     37 util.inherits(ActionStore, Action);
     38 
     39 /*:nodoc:*
     40  * ActionStore#call(parser, namespace, values, optionString) -> Void
     41  * - parser (ArgumentParser): current parser
     42  * - namespace (Namespace): namespace for output data
     43  * - values (Array): parsed values
     44  * - optionString (Array): input option string(not parsed)
     45  *
     46  * Call the action. Save result in namespace object
     47  **/
     48 ActionStore.prototype.call = function (parser, namespace, values) {
     49   namespace.set(this.dest, values);
     50 };