@foal/cli
Version:
CLI tool for FoalTS
34 lines (33 loc) • 970 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.UtilService = void 0;
/**
* Service for utility functions.
*/
class UtilService {
/**
* Parse command line arguments from argv array.
*
* @param {string[]} argv - The command line arguments array (typically process.argv)
* @returns {Record<string, any>} An object containing the parsed arguments
*/
getCommandLineArguments(argv) {
const args = argv.splice(4);
const result = {};
args.forEach(keyAndValue => {
const [key, value] = keyAndValue.split('=');
if (typeof value === 'undefined') {
result[key] = true;
return;
}
try {
result[key] = JSON.parse(value);
}
catch (error) {
result[key] = value;
}
});
return result;
}
}
exports.UtilService = UtilService;