2020-02-19 08:11:32 +01:00
|
|
|
'use strict';
|
|
|
|
|
2023-03-08 14:08:57 +01:00
|
|
|
const camelToSnake = (s) => s.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase());
|
2020-02-19 08:11:32 +01:00
|
|
|
|
|
|
|
exports.stringify = ({ command = '', flags = {}, reason = '' }) => {
|
|
|
|
const flagS = Object.entries(flags)
|
2023-03-08 14:08:57 +01:00
|
|
|
.flatMap(([key, value]) => {
|
2020-02-19 08:11:32 +01:00
|
|
|
switch (value) {
|
2023-03-08 14:08:57 +01:00
|
|
|
case null:
|
|
|
|
case false:
|
|
|
|
case undefined: // eslint-disable-line no-undefined
|
|
|
|
return [];
|
|
|
|
case true:
|
|
|
|
return ['-' + camelToSnake(key)];
|
|
|
|
default:
|
|
|
|
return [`-${camelToSnake(key)}=${value}`];
|
2020-02-19 08:11:32 +01:00
|
|
|
}
|
2023-03-08 14:08:57 +01:00
|
|
|
})
|
|
|
|
.join(' ');
|
|
|
|
return ['/' + command, flagS, reason].filter(Boolean).join(' ');
|
2020-02-19 08:11:32 +01:00
|
|
|
};
|