123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 'use strict';
- var c = require('./const');
- var Action = module.exports = function Action(options) {
- options = options || {};
- this.optionStrings = options.optionStrings || [];
- this.dest = options.dest;
- this.nargs = typeof options.nargs !== 'undefined' ? options.nargs : null;
- this.constant = typeof options.constant !== 'undefined' ? options.constant : null;
- this.defaultValue = options.defaultValue;
- this.type = typeof options.type !== 'undefined' ? options.type : null;
- this.choices = typeof options.choices !== 'undefined' ? options.choices : null;
- this.required = typeof options.required !== 'undefined' ? options.required : false;
- this.help = typeof options.help !== 'undefined' ? options.help : null;
- this.metavar = typeof options.metavar !== 'undefined' ? options.metavar : null;
- if (!(this.optionStrings instanceof Array)) {
- throw new Error('optionStrings should be an array');
- }
- if (typeof this.required !== 'undefined' && typeof this.required !== 'boolean') {
- throw new Error('required should be a boolean');
- }
- };
- Action.prototype.getName = function () {
- if (this.optionStrings.length > 0) {
- return this.optionStrings.join('/');
- } else if (this.metavar !== null && this.metavar !== c.SUPPRESS) {
- return this.metavar;
- } else if (typeof this.dest !== 'undefined' && this.dest !== c.SUPPRESS) {
- return this.dest;
- }
- return null;
- };
- Action.prototype.isOptional = function () {
- return !this.isPositional();
- };
- Action.prototype.isPositional = function () {
- return (this.optionStrings.length === 0);
- };
- Action.prototype.call = function () {
- throw new Error('.call() not defined');
- };
|