Initial commit
[yaffs-website] / node_modules / argparse / lib / argument / group.js
1 /** internal
2  * class ArgumentGroup
3  *
4  * Group arguments.
5  * By default, ArgumentParser groups command-line arguments
6  * into “positional arguments” and “optional arguments”
7  * when displaying help messages. When there is a better
8  * conceptual grouping of arguments than this default one,
9  * appropriate groups can be created using the addArgumentGroup() method
10  *
11  * This class inherited from [[ArgumentContainer]]
12  **/
13 'use strict';
14
15 var util = require('util');
16
17 var ActionContainer = require('../action_container');
18
19
20 /**
21  * new ArgumentGroup(container, options)
22  * - container (object): main container
23  * - options (object): hash of group options
24  *
25  * #### options
26  * - **prefixChars**  group name prefix
27  * - **argumentDefault**  default argument value
28  * - **title**  group title
29  * - **description** group description
30  *
31  **/
32 var ArgumentGroup = module.exports = function ArgumentGroup(container, options) {
33
34   options = options || {};
35
36   // add any missing keyword arguments by checking the container
37   options.conflictHandler = (options.conflictHandler || container.conflictHandler);
38   options.prefixChars = (options.prefixChars || container.prefixChars);
39   options.argumentDefault = (options.argumentDefault || container.argumentDefault);
40
41   ActionContainer.call(this, options);
42
43   // group attributes
44   this.title = options.title;
45   this._groupActions = [];
46
47   // share most attributes with the container
48   this._container = container;
49   this._registries = container._registries;
50   this._actions = container._actions;
51   this._optionStringActions = container._optionStringActions;
52   this._defaults = container._defaults;
53   this._hasNegativeNumberOptionals = container._hasNegativeNumberOptionals;
54   this._mutuallyExclusiveGroups = container._mutuallyExclusiveGroups;
55 };
56 util.inherits(ArgumentGroup, ActionContainer);
57
58
59 ArgumentGroup.prototype._addAction = function (action) {
60   // Parent add action
61   action = ActionContainer.prototype._addAction.call(this, action);
62   this._groupActions.push(action);
63   return action;
64 };
65
66
67 ArgumentGroup.prototype._removeAction = function (action) {
68   // Parent remove action
69   ActionContainer.prototype._removeAction.call(this, action);
70   var actionIndex = this._groupActions.indexOf(action);
71   if (actionIndex >= 0) {
72     this._groupActions.splice(actionIndex, 1);
73   }
74 };
75