2 * class ActionAppendConstant
4 * This stores a list, and appends the value specified by
5 * the const keyword argument to the list.
6 * (Note that the const keyword argument defaults to null.)
7 * The 'appendConst' action is typically useful when multiple
8 * arguments need to store constants to the same list.
10 * This class inherited from [[Action]]
15 var util = require('util');
17 var Action = require('../../action');
20 * new ActionAppendConstant(options)
21 * - options (object): options hash see [[Action.new]]
24 var ActionAppendConstant = module.exports = function ActionAppendConstant(options) {
25 options = options || {};
27 if (typeof options.constant === 'undefined') {
28 throw new Error('constant option is required for appendAction');
30 Action.call(this, options);
32 util.inherits(ActionAppendConstant, Action);
35 * ActionAppendConstant#call(parser, namespace, values, optionString) -> Void
36 * - parser (ArgumentParser): current parser
37 * - namespace (Namespace): namespace for output data
38 * - values (Array): parsed values
39 * - optionString (Array): input option string(not parsed)
41 * Call the action. Save result in namespace object
43 ActionAppendConstant.prototype.call = function (parser, namespace) {
44 var items = [].concat(namespace[this.dest] || []);
45 items.push(this.constant);
46 namespace.set(this.dest, items);