const yargs = require('yargs');
function initializeOptions(argv) {
// Default values
const options = {
name: 'World', // Default name
greeting: 'Hello', // Default greeting
uppercase: false, // Default uppercase
count: 1 // Default count
};
// Override defaults with command-line arguments
if (argv.name) {
options.name = argv.name;
}
if (argv.greeting) {
options.greeting = argv.greeting;
}
if (argv.uppercase !== undefined) {
options.uppercase = argv.uppercase;
}
if (argv.count !== undefined) {
options.count = argv.count;
}
return options; // Return the initialized options object
}
// Example usage (for testing purposes)
// const argv = yargs.argv;
// const initializedOptions = initializeOptions(argv);
// console.log(initializedOptions);
Add your comment