4 * This action stores a list, and appends each argument value to the list.
5 * This is useful to allow an option to be specified multiple times.
6 * This class inherided from [[Action]]
12 var util = require('util');
14 var Action = require('../action');
17 var c = require('../const');
20 * new ActionAppend(options)
21 * - options (object): options hash see [[Action.new]]
23 * Note: options.nargs should be optional for constants
24 * and more then zero for other
26 var ActionAppend = module.exports = function ActionAppend(options) {
27 options = options || {};
28 if (this.nargs <= 0) {
29 throw new Error('nargs for append actions must be > 0; if arg ' +
30 'strings are not supplying the value to append, ' +
31 'the append const action may be more appropriate');
33 if (!!this.constant && this.nargs !== c.OPTIONAL) {
34 throw new Error('nargs must be OPTIONAL to supply const');
36 Action.call(this, options);
38 util.inherits(ActionAppend, Action);
41 * ActionAppend#call(parser, namespace, values, optionString) -> Void
42 * - parser (ArgumentParser): current parser
43 * - namespace (Namespace): namespace for output data
44 * - values (Array): parsed values
45 * - optionString (Array): input option string(not parsed)
47 * Call the action. Save result in namespace object
49 ActionAppend.prototype.call = function (parser, namespace, values) {
50 var items = (namespace[this.dest] || []).slice();
52 namespace.set(this.dest, items);