2017-12-21 17:40:13 +00:00
|
|
|
import { OptionDefinition } from 'capitano';
|
|
|
|
import * as _ from 'lodash';
|
|
|
|
import * as ent from 'ent';
|
|
|
|
|
|
|
|
export function getOptionPrefix(signature: string) {
|
|
|
|
if (signature.length > 1) {
|
|
|
|
return '--';
|
|
|
|
} else {
|
|
|
|
return '-';
|
|
|
|
}
|
2018-01-04 14:07:55 +00:00
|
|
|
}
|
2017-12-21 17:40:13 +00:00
|
|
|
|
|
|
|
export function getOptionSignature(signature: string) {
|
|
|
|
return `${getOptionPrefix(signature)}${signature}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function parseSignature(option: OptionDefinition) {
|
|
|
|
let result = getOptionSignature(option.signature);
|
|
|
|
|
2018-01-04 16:17:43 +00:00
|
|
|
if (_.isArray(option.alias)) {
|
|
|
|
for (let alias of option.alias) {
|
|
|
|
result += `, ${getOptionSignature(alias)}`;
|
2017-12-21 17:40:13 +00:00
|
|
|
}
|
2018-01-04 16:17:43 +00:00
|
|
|
} else if (_.isString(option.alias)) {
|
|
|
|
result += `, ${getOptionSignature(option.alias)}`;
|
2017-12-21 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 16:17:43 +00:00
|
|
|
if (option.parameter) {
|
2017-12-21 17:40:13 +00:00
|
|
|
result += ` <${option.parameter}>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ent.encode(result);
|
2018-01-04 14:07:55 +00:00
|
|
|
}
|