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
11 * This class inherited from [[ArgumentContainer]]
15 var util = require('util');
17 var ActionContainer = require('../action_container');
21 * new ArgumentGroup(container, options)
22 * - container (object): main container
23 * - options (object): hash of group options
26 * - **prefixChars** group name prefix
27 * - **argumentDefault** default argument value
28 * - **title** group title
29 * - **description** group description
32 var ArgumentGroup = module.exports = function ArgumentGroup(container, options) {
34 options = options || {};
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);
41 ActionContainer.call(this, options);
44 this.title = options.title;
45 this._groupActions = [];
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;
56 util.inherits(ArgumentGroup, ActionContainer);
59 ArgumentGroup.prototype._addAction = function (action) {
61 action = ActionContainer.prototype._addAction.call(this, action);
62 this._groupActions.push(action);
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);