#!/usr/bin/env node
/**
* Strips metadata from CLI arguments for monitoring.
*
* @param {string[]} args The array of command-line arguments.
* @returns {object} An object containing the stripped arguments.
*/
function stripMetadata(args) {
const strippedArgs = {};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
const trimmedArg = arg.trim(); // Remove leading/trailing whitespace
if (trimmedArg.startsWith('--')) {
const key = trimmedArg.slice(2); // Remove the '--' prefix
strippedArgs[key] = args[i + 1] || null; // Store value, null if no value provided
i++; // Skip the value
} else {
strippedArgs[trimmedArg] = true; // Store boolean flag
}
}
return strippedArgs;
}
// Example usage (for testing - remove for production)
if (require.main === module) {
const args = process.argv.slice(2); // Get arguments from process.argv
const stripped = stripMetadata(args);
console.log(JSON.stringify(stripped, null, 2));
}
module.exports = stripMetadata;
Add your comment