1. const { exec } = require('child_process');
  2. const readline = require('readline').createInterface({
  3. input: process.stdin,
  4. output: process.stdout,
  5. });
  6. /**
  7. * Teardown function for debugging HTML documents.
  8. * Executes the specified command in the shell.
  9. * @param {string} command The command to execute.
  10. */
  11. function teardown(command) {
  12. console.log(`Executing: ${command}`);
  13. exec(command, (error, stdout, stderr) => {
  14. if (error) {
  15. console.error(`exec error: ${error}`);
  16. return;
  17. }
  18. if (stderr) {
  19. console.error(`exec stderr: ${stderr}`);
  20. }
  21. console.log(`exec stdout: ${stdout}`);
  22. });
  23. }
  24. /**
  25. * CLI interface for teardown commands.
  26. */
  27. function cli() {
  28. readline.question('Enter teardown command (or "exit"): ', (command) => {
  29. if (command === 'exit') {
  30. readline.close();
  31. return;
  32. }
  33. teardown(command);
  34. cli(); // Continue prompting for commands
  35. });
  36. }
  37. // Start the CLI
  38. cli();

Add your comment