#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { program } = require('commander');
program
.version('1.0.0')
.description('Executes text files for internal use.')
.argument('[filePath]', 'Path to the text file to execute')
.action((filePath) => {
try {
// Validate file extension
if (!path.extname(filePath).endsWith('.txt')) {
throw new Error('File must have a .txt extension.');
}
// Read the file content
const fileContent = fs.readFileSync(filePath, 'utf8');
// Execute the file content (using eval - use with caution!)
try {
eval(fileContent);
} catch (error) {
console.error('Error executing file:', error.message);
}
} catch (error) {
console.error('Error:', error.message);
}
});
program.parse(process.argv);
Add your comment