clipanion
Version:
Type-safe CLI library / framework with no runtime dependencies
31 lines (28 loc) • 1.02 kB
JavaScript
import { makeCommandOption, rerouteArguments } from './utils.mjs';
function Boolean(descriptor, initialValueBase, optsBase) {
const [initialValue, opts] = rerouteArguments(initialValueBase, optsBase !== null && optsBase !== void 0 ? optsBase : {});
const optNames = descriptor.split(`,`);
const nameSet = new Set(optNames);
return makeCommandOption({
definition(builder) {
builder.addOption({
names: optNames,
allowBinding: false,
arity: 0,
hidden: opts.hidden,
description: opts.description,
required: opts.required,
});
},
transformer(builer, key, state) {
let currentValue = initialValue;
for (const { name, value } of state.options) {
if (!nameSet.has(name))
continue;
currentValue = value;
}
return currentValue;
},
});
}
export { Boolean };