@jil/args
Version:
A convention based argument parsing and formatting library, with strict validation checks
37 lines • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processShortOptionGroup = void 0;
const errors_1 = require("../errors");
const expandShortOption_1 = require("./expandShortOption");
/**
* Expand a group of short option names to a list of long option names.
*/
function processShortOptionGroup(group, configs, options, map, loose) {
[...group].forEach(short => {
const name = (0, expandShortOption_1.expandShortOption)(short, map, loose);
const config = configs[name];
// Loose mode, always be a flag
if (loose && !config) {
options[name] = true;
// Unknown option
}
else if (!config || config.type === 'string') {
throw new errors_1.ArgsError('GROUP_UNSUPPORTED_TYPE');
// Boolean option, flag
}
else if (config.type === 'boolean') {
options[name] = true;
// Number option, counter
}
else if (config.type === 'number') {
if (config.count) {
options[name] = Number(options[name]) + 1;
}
else {
throw new errors_1.ArgsError('GROUP_REQUIRED_COUNT');
}
}
});
}
exports.processShortOptionGroup = processShortOptionGroup;
//# sourceMappingURL=processShortOptionGroup.js.map