1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict';
- var util = require('util');
- var Action = require('../action');
- var c = require('../const');
- var ActionAppend = module.exports = function ActionAppend(options) {
- options = options || {};
- if (this.nargs <= 0) {
- throw new Error('nargs for append actions must be > 0; if arg ' +
- 'strings are not supplying the value to append, ' +
- 'the append const action may be more appropriate');
- }
- if (!!this.constant && this.nargs !== c.OPTIONAL) {
- throw new Error('nargs must be OPTIONAL to supply const');
- }
- Action.call(this, options);
- };
- util.inherits(ActionAppend, Action);
- ActionAppend.prototype.call = function (parser, namespace, values) {
- var items = (namespace[this.dest] || []).slice();
- items.push(values);
- namespace.set(this.dest, items);
- };
|